管线命令 cut grep
生活随笔
收集整理的這篇文章主要介紹了
管线命令 cut grep
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
管線命令僅會(huì)處理 standard output,對(duì)于 standard error output 會(huì)予以忽略
管線命令必須要能夠接受來自前一個(gè)命令的數(shù)據(jù)成為 standard input 繼續(xù)處理才行。
[root@www ~]# uniq [-ic]選項(xiàng)與參數(shù):-i ?:忽略大小寫字符的不同;-c ?:進(jìn)行計(jì)數(shù)
[root@www ~]# wc [-lwm]選項(xiàng)與參數(shù):-l ?:僅列出行;-w ?:僅列出多少字(英文單字);-m ?:多少字符;[root@www ~]# tee [-a] file選項(xiàng)與參數(shù):-a ?:以累加 (append) 的方式,將數(shù)據(jù)加入 file 當(dāng)中![root@www ~]# last | tee last.list | cut -d " " -f1# 這個(gè)范例可以讓我們將 last 的輸出存一份到 last.list 文件中;[root@www ~]# ls -l /home | tee ~/homefile | more# 這個(gè)范例則是將 ls 的數(shù)據(jù)存一份到 ~/homefile ,同時(shí)屏幕也有輸出信息![root@www ~]# ls -l / | tee -a ~/homefile | more# 要注意! tee 后接的文件會(huì)被覆蓋,若加上 -a 這個(gè)選項(xiàng)則能將信息累加。
tr
tr 可以用來刪除一段信息當(dāng)中的文字,或者是進(jìn)行文字信息的替換!
| [root@www ~]# tr [-ds] SET1 ...選項(xiàng)與參數(shù):-d ?:刪除信息當(dāng)中的 SET1 這個(gè)字符串;-s ?:取代掉重復(fù)的字符!范例一:將 last 輸出的信息中,所有的小寫變成大寫字符: [root@www ~]# last | tr '[a-z]' '[A-Z]'# 事實(shí)上,沒有加上單引號(hào)也是可以運(yùn)行的,如:『 last | tr [a-z] [A-Z] 』范例二:將 /etc/passwd 輸出的信息中,將冒號(hào) (:) 刪除 [root@www ~]# cat /etc/passwd | tr -d ':'范例三:將 /etc/passwd 轉(zhuǎn)存成 dos 斷行到 /root/passwd 中,再將 ^M 符號(hào)刪除 [root@www ~]# cp /etc/passwd /root/passwd && unix2dos /root/passwd [root@www ~]# file /etc/passwd /root/passwd /etc/passwd: ?ASCII text /root/passwd: ASCII text, with CRLF line terminators <==就是 DOS 斷行 [root@www ~]# cat /root/passwd | tr -d '\r' > /root/passwd.linux# 那個(gè) \r 指的是 DOS 的斷行字符,關(guān)于更多的字符,請參考 man tr [root@www ~]# ll /etc/passwd /root/passwd* -rw-r--r-- 1 root root 1986 Feb ?6 17:55 /etc/passwd -rw-r--r-- 1 root root 2030 Feb ?7 15:55 /root/passwd -rw-r--r-- 1 root root 1986 Feb ?7 15:57 /root/passwd.linux # 處理過后,發(fā)現(xiàn)文件大小與原本的 /etc/passwd 就一致了! |
[root@www ~]# join [-ti12] file1 file2選項(xiàng)與參數(shù):-t ?:join 默認(rèn)以空格符分隔數(shù)據(jù),并且比對(duì)『第一個(gè)字段』的數(shù)據(jù), ? ? ?如果兩個(gè)文件相同,則將兩筆數(shù)據(jù)聯(lián)成一行,且第一個(gè)字段放在第一個(gè)!-i ?:忽略大小寫的差異;-1 ?:這個(gè)是數(shù)字的 1 ,代表『第一個(gè)文件要用那個(gè)字段來分析』的意思;-2 ?:代表『第二個(gè)文件要用那個(gè)字段來分析』的意思。
[root@www ~]# paste [-d] file1 file2選項(xiàng)與參數(shù):-d ?:后面可以接分隔字符。默認(rèn)是以 [tab] 來分隔的!- ? :如果 file 部分寫成 - ,表示來自 standard input 的數(shù)據(jù)的意思。
[root@www ~]# expand [-t] file選項(xiàng)與參數(shù):-t ?:后面可以接數(shù)字。一般來說,一個(gè) tab 按鍵可以用 8 個(gè)空格鍵取代。 ? ? ?我們也可以自行定義一個(gè) [tab] 按鍵代表多少個(gè)字符呢!
[root@www ~]# split [-bl] file PREFIX選項(xiàng)與參數(shù):-b ?:后面可接欲分割成的文件大小,可加單位,例如 b, k, m 等;-l ?:以行數(shù)來進(jìn)行分割。PREFIX :代表前導(dǎo)符的意思,可作為分割文件的前導(dǎo)文字。
[root@www ~]# xargs [-0epn] command選項(xiàng)與參數(shù):-0 ?:如果輸入的 stdin 含有特殊字符,例如 `, \, 空格鍵等等字符時(shí),這個(gè) -0 參數(shù) ? ? ?可以將他還原成一般字符。這個(gè)參數(shù)可以用于特殊狀態(tài)喔!-e ?:這個(gè)是 EOF (end of file) 的意思。后面可以接一個(gè)字符串,當(dāng) xargs 分析到 ? ? ?這個(gè)字符串時(shí),就會(huì)停止繼續(xù)工作!-p ?:在運(yùn)行每個(gè)命令的 argument 時(shí),都會(huì)詢問使用者的意思;-n ?:后面接次數(shù),每次 command 命令運(yùn)行時(shí),要使用幾個(gè)參數(shù)的意思。看范例三。當(dāng) xargs 后面沒有接任何的命令時(shí),默認(rèn)是以 echo 來進(jìn)行輸出喔!
轉(zhuǎn)載于:https://blog.51cto.com/libao2235/1413529
總結(jié)
以上是生活随笔為你收集整理的管线命令 cut grep的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Sql Server 2008R2版本中
- 下一篇: 安装CocoaPods