Linux tr command All In One

Posted xgqfrms

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux tr command All In One相关的知识,希望对你有一定的参考价值。

Linux tr command All In One tr 转义或删除字符

Linux tr command All In One

tr 转义或删除字符

tr

$ man tr > man-tr.md

$ cat man-tr.md
TR(1)                                             User Commands                                            TR(1)

NAME
       tr - translate or delete characters

SYNOPSIS
       tr [OPTION]... SET1 [SET2]

DESCRIPTION
       Translate, squeeze, and/or delete characters from standard input, writing to standard output.

       -c, -C, --complement
              use the complement of SET1

       -d, --delete
              delete characters in SET1, do not translate

       -s, --squeeze-repeats
              replace  each  sequence  of  a repeated character that is listed in the last specified SET, with a
              single occurrence of that character

       -t, --truncate-set1
              first truncate SET1 to length of SET2

       --help display this help and exit

       --version
              output version information and exit

       SETs are specified as strings of characters.  Most represent themselves.  Interpreted sequences are:

       \\NNN   character with octal value NNN (1 to 3 octal digits)

       \\\\     backslash

       \\a     audible BEL

       \\b     backspace

       \\f     form feed

       \\n     new line

       \\r     return

       \\t     horizontal tab

       \\v     vertical tab

       CHAR1-CHAR2
              all characters from CHAR1 to CHAR2 in ascending order

       [CHAR*]
              in SET2, copies of CHAR until length of SET1

       [CHAR*REPEAT]
              REPEAT copies of CHAR, REPEAT octal if starting with 0

       [:alnum:]
              all letters and digits

       [:alpha:]
              all letters

       [:blank:]
              all horizontal whitespace

       [:cntrl:]
              all control characters

       [:digit:]
              all digits

       [:graph:]
              all printable characters, not including space

       [:lower:]
              all lower case letters

       [:print:]
              all printable characters, including space

       [:punct:]
              all punctuation characters

       [:space:]
              all horizontal or vertical whitespace

       [:upper:]
              all upper case letters

       [:xdigit:]
              all hexadecimal digits

       [=CHAR=]
              all characters which are equivalent to CHAR

       Translation occurs if -d is not given and both SET1 and SET2 appear.  -t may be used only when  translat‐
       ing.  SET2 is extended to length of SET1 by repeating its last character as necessary.  Excess characters
       of SET2 are ignored.  Only [:lower:] and [:upper:] are guaranteed to expand in ascending order;  used  in
       SET2  while  translating,  they  may  only be used in pairs to specify case conversion.  -s uses the last
       specified SET, and occurs after translation or deletion.

AUTHOR
       Written by Jim Meyering.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2020  Free  Software  Foundation,  Inc.   License  GPLv3+:  GNU  GPL  version  3  or  later
       <https://gnu.org/licenses/gpl.html>.
       This  is  free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent
       permitted by law.

SEE ALSO
       Full documentation <https://www.gnu.org/software/coreutils/tr>
       or available locally via: info \'(coreutils) tr invocation\'

GNU coreutils 8.32                               September 2020                                            TR(1)
pi@raspberrypi:~/Desktop/man-docs $ 

demos

pdf crawler / pdf 爬虫

#!/bin/bash 绝对路径 ⚠️

#!/usr/bin/env bash 相对路径 ✅

#!/usr/bin/env bash

# 下载目录
downdir="/Users/xgqfrms-mbp/Documents/swift-ui/Memorize/000-xyz/pdfs/"

# $1 是传递给 shell 的第一个参数
# read line 按行读取文件
cat $1 | while read line
do
  # shell 变量需要使用双引号包裹, 或 echo $line
  echo "$line"
  cd $downdir
  str=$line
  # 按行分割,每行一个, 正则表达式:字符串转数组
  array=($str//;/ )
  echo "$array"
  url=$array[0]
  # tr 删除换行字符 ✅
  filename=$(echo $array[1] | tr -d \'\\r\')
  # filename=$(echo "l" + $index + ".pdf" | tr -d \'\\r\')
  # filename=$(echo "l$index.pdf" | tr -d \'\\r\')
  # cURL 执行下载, -o 输出文件
  curl $url -o $filename
done

# exit 0

# mkdir pdfs
$ bash ./auto-download-pdfs.sh cs193p.txt
# OR, 可执行脚本
$ chmod +x ./auto-download-pdfs.sh
$ ./auto-download-pdfs.sh cs193p.txt

cs193p.txt

https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l1.pdf;l1.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l2.pdf;l2.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l3.pdf;l3.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l4.pdf;l4.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l5.pdf;l5.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l6.pdf;l6.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l7.pdf;l7.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l8.pdf;l8.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l9.pdf;l9.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l10.pdf;l10.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l11.pdf;l11.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l12.pdf;l12.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l13.pdf;l12.pdf
https://cs193p.sites.stanford.edu/sites/g/files/sbiybj16636/files/media/file/l14.pdf;l14.pdf

(

Linux shell command screen All In One

Linux shell command screen All In One usbserial USB usbmodem

Linux shell command screen All In One

screen

# screen
$ screen --help
Use: screen [-opts] [cmd [args]]
 or: screen -r [host.tty]

Options:
-a            Force all capabilities into each window\'s termcap.
-A -[r|R]     Adapt all windows to the new display width & height.
-c file       Read configuration file instead of \'.screenrc\'.
-d (-r)       Detach the elsewhere running screen (and reattach here).
-dmS name     Start as daemon: Screen session in detached mode.
-D (-r)       Detach and logout remote (and reattach here).
-D -RR        Do whatever is needed to get a screen session.
-e xy         Change command characters.
-f            Flow control on, -fn = off, -fa = auto.
-h lines      Set the size of the scrollback history buffer.
-i            Interrupt output sooner when flow control is on.
-list         or -ls. Do nothing, just list our SockDir.
-L            Turn on output logging.
-m            ignore $STY variable, do create a new screen session.
-O            Choose optimal output rather than exact vt100 emulation.
-p window     Preselect the named window if it exists.
-q            Quiet startup. Exits with non-zero return code if unsuccessful.
-r            Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-s shell      Shell to execute rather than $SHELL.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title      Set title. (window\'s name).
-T term       Use term as $TERM for windows, rather than "screen".
-U            Tell screen to use UTF-8 encoding.
-v            Print "Screen version 4.00.03 (FAU) 23-Oct-06".
-wipe         Do nothing, just clean up SockDir.
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.


demos

usbserial

# /dev => devices ✅
$ cd /dev && ls | grep "cu."
$ cd /dev && ls | grep "tty."

# usbserial
$ screen /dev/cu.usbserial

$ cd /dev && ls | grep "cu."
cu.BLTH
cu.Bluetooth-Incoming-Port
$ /dev screen /dev/cu.B
cu.BLTH%                     cu.Bluetooth-Incoming-Port%

https://youtu.be/RkOtub1H944?t=167

usbmodem

# usb
$ lsusb

# macOS 查看真实的 tty.usbmodem
# /dev => devices ✅
$ cd /dev && ls | grep "usbmodem"