一定躏、tr命令
tr
命令可以用來刪除一段文本中的某些文字英支,或者將其進(jìn)行轉(zhuǎn)換食拜。
-
tr
使用方法:
Usage: tr [OPTION]... SET1 [SET2]
Translate, squeeze, and/or delete characters from standard input,
writing to standard output.
-
tr
常用選項(xiàng):
選項(xiàng) | 說明 |
---|---|
-d |
刪除和SET1匹配的字符蔽介,注意不是全詞匹配也不是按字符順序匹配 |
-s |
去除SET1指定的在輸入文本中連續(xù)并重復(fù)的字符 |
-
tr
常見的使用方法:
shiyanlou:~/ $ echo 'hello 2e31ldon' | tr -d '[:digit:]'
hello eldon
shiyanlou:~/ $ echo 'hello eeldon' | tr -s '[:digit:]'
hello eeldon
shiyanlou:~/ $ echo 'hello eeldon' | tr -s '[:alnum:]'
helo eldon
shiyanlou:~/ $ echo 'hello eldon' | tr '[:upper:]' '[:lower:]'
hello eldon
shiyanlou:~/ $ echo 'heLlo ElDon' | tr '[:upper:]' '[:lower:]'
hello eldon
二、col命令
col
命令可以將Tab
換成對(duì)等數(shù)量的空格鍵献幔,或反轉(zhuǎn)這個(gè)操作懂傀。
-
col
使用方法:
col [option]
-
col
常用選項(xiàng):
選項(xiàng) | 說明 |
---|---|
-x |
將Tab 轉(zhuǎn)換為空格 |
-h |
將空格轉(zhuǎn)換為Tab
|
-
col
常見使用方法:
shiyanlou:~/ $ cat eldon.log | col -x > eldon1.log
shiyanlou:~/ $ cat /etc/protocols| col -x | cat -A
三、jion命令
join
命令就是講兩個(gè)文件中包含相同內(nèi)容的那一行合并在一起蜡感。
-
join
使用方法:
Usage: join [OPTION]... FILE1 FILE2
For each pair of input lines with identical join fields, write a line to
standard output. The default join field is the first, delimited
by whitespace. When FILE1 or FILE2 (not both) is -, read standard input.
-
join
常用選項(xiàng):
選項(xiàng) | 說明 |
---|---|
-t |
指定分隔符蹬蚁,默認(rèn)為空格 |
-i |
忽略大小寫的差異 |
-1 |
指明第一個(gè)文件要用哪個(gè)字段來對(duì)比,默認(rèn)對(duì)比第一個(gè)字段 |
-2 |
指明第二個(gè)文件要用哪個(gè)字段來對(duì)比郑兴,默認(rèn)對(duì)比第一個(gè)字段 |
-
join
常見使用方法:
shiyanlou:~/ $ sudo join -t ':' /etc/passwd /etc/shadow
四犀斋、paste命令
paste
命令與join
類似,在不對(duì)比數(shù)據(jù)的情況下情连,簡單的將多個(gè)文件合并在一起叽粹,以Tab
隔開。
-
paste
使用方法:
Usage: paste [OPTION]... [FILE]...
Write lines consisting of the sequentially corresponding lines from
each FILE, separated by TABs, to standard output.
With no FILE, or when FILE is -, read standard input.
-
paste
常用選項(xiàng):
選項(xiàng) | 說明 |
---|---|
-d |
指定分隔符蒙具,默認(rèn)為Tab
|
-s |
不合并到一行 |
-
paste
常見使用方法:
shiyanlou:~/ $ sudo paste /etc/passwd /etc/shadow | head -n 2
root:x:0:0:root:/root:/bin/bashroot:*:16583:0:99999:7:::
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologindaemon:*:16583:0:99999:7:::
shiyanlou:~/ $ sudo paste -d "&" /etc/passwd /etc/shadow | head -n 2
root:x:0:0:root:/root:/bin/bash&root:*:16583:0:99999:7:::
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin&daemon:*:16583:0:99999:7:::
shiyanlou:~/ $
輕松一刻:
shiyanlou:~/ $ sudo apt-get install ninvaders
shiyanlou:~/ $ ninvaders