文本處理工具
文件查看命令:cat cat [OPTION]… [FILE]…
-E: 顯示行結束符$
-n: 對顯示出的每一行進行編號
-A:顯示所有控制符
-b:非空行編號
-s:壓縮連續的空行成一行
[root@centous1 soft]# echo "1 2 3 4 5 6" >> f1 [root@centous1 soft]# cat f1 1 2 3 4 5 6
more: 分頁查看文件 more [OPTIONS…] FILE…
-d: 顯示翻頁及退出提示
less:一頁一頁地查看文件或STDIN輸出 查看時有用的命令包括: /文本 搜索 文本
n/N 跳到下一個 或 上一個匹配
less 命令是man命令使用的分頁器
注;平時的用法就是,cat FILE | more/less
head head [OPTION]… [FILE]…
-c #: 指定獲取前#字節
-n #: 指定獲取前#行
-#: 指定行數 ?
tail tail [OPTION]… [FILE]…
-c #: 指定獲取后#字節
-n #: 指定獲取后#行
-#:指定行數
-f: 跟蹤顯示文件新追加的內容,常用日志監控
[root@centous1 soft]# cat f1 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 [root@centous1 soft]# cat f1 | head -n 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 [root@centous1 soft]# cat f1 | tail -n 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 [root@centous1 soft]# cat f1 | head -n 4 | tail -n 1 1 2 3 4 5 6 7
cut [OPTION]… [FILE]…
-d DELIMITER: 指明分隔符,默認tab -f FILEDS:
#: 第#個字段 #,#[,#]:離散的多個字段,例如1,3,6 #-#:連續的多個字段, 例如1-6 混合使用:1-3,7
-c 按字符切割 –output-delimiter=STRING指定輸出分隔符
[root@centous1 soft]# cat f1 | cut -d " " -f 1 1 1 1 1 1 1 [root@centous1 soft]# cat f1 | cut -d " " -f 1,4,7 1 4 1 4 1 4 1 4 7 1 4 7 1 4 7
注;這里的意思是,cut -d 以空格為分隔符進行切割,-f則是顯示第幾行,以逗號隔開
wc 計數單詞總數、行總數、字節總數和字符總數 ?可以對文件或STDIN中的數據運行
使用 -l 來只計數行數 ?
使用 -w 來只計數單詞總數 ?
使用 -c 來只計數字節總數 ?
使用 -m 來只計數字符總數
[root@centous1 soft]# cat f1 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 [root@centous1 soft]# wc -l f1 6 f1 [root@centous1 soft]# wc -w f1 39 f1 [root@centous1 soft]# wc -m f1 79 f1 [root@centous1 soft]# wc -c f1 79 f1
sort [options] file(s) ?
常用選項 ?
-r 執行反方向(由上至下)整理 ?
-n 執行按數字大小整理 ?
-f 選項忽略(fold)字符串中的字符大小寫 ?
-u 選項(獨特,unique)刪除輸出中的重復行 ?
-t c 選項使用c做為字段界定符 ?
-k X 選項按照使用c字符分隔的X列來整理能夠使用多次
[root@centous1 soft]# cat f1 | sort -r 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 [root@centous1 soft]# cat f1 | sort -n 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 [root@centous1 soft]# echo "1 2 3 4" >> f1 [root@centous1 soft]# cat f1 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 2 3 4 [root@centous1 soft]# sort -u f1 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 [root@centous1 soft]# cat /etc/passwd | sort -t ":" -k 3n | tail -n 10 abrt:x:173:173::/etc/abrt:/sbin/nologin saslauth:x:499:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin zabbix:x:500:500::/home/zabbix:/bin/bash testuser:x:4321:0::/home/test:/bin/csh text:x:4322:4322::/home/text:/bin/bash user1:x:4323:4323::/home/user1:/bin/bash user2:x:4324:4324::/home/user2:/bin/bash testbash:x:4326:4326::/home/testbash:/bin/bash basher:x:4327:4327::/home/basher:/bin/bash nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
uniq命令:從輸入中刪除重復的前后相接的行 ?
uniq [OPTION]… [FILE]…
-c: 顯示每行重復出現的次數
-d: 僅顯示重復過的行
-u: 僅顯示不曾重復的行 連續且完全相同方為重復 ?
常和sort 命令一起配合使用: sort userlist.txt | uniq -c
列:
統計當前連接本機的每個遠程主機IP的連接數,并按從大 到小排序
netstat -nt | tr -s " " ";" | cut -d ";" -f5 | uniq -c | sort -n | head -n -2
diff
?比較兩個文件之間的區別 $ diff foo.conf-broken foo.conf-works
5c5
< use_widgets = no — >
use_widgets = yes
?注明第5行有區別(改變)
diff 命令的輸出被保存在一種叫做“補丁”的文件中 ?
使用 -u 選項來輸出“統一的(unified)”diff格式文 件,最適用于補丁文件
原創文章,作者:forest,如若轉載,請注明出處:http://www.www58058.com/30467