centos文本查看及处理相关的常用命令
生活随笔
收集整理的這篇文章主要介紹了
centos文本查看及处理相关的常用命令
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.文本查看cat less more:
(1)使用cat命令
[root@62q ~]# cat /etc/passwd [root@62q ~]# cat -n test # -n顯示行號1 18552 18553 794(2)也可以使用less命令可以像man命令一樣上下翻屏查看:
[root@62q ~]# less /etc/passwd(3)查看前n行:head
[root@62q ~]# head test #不加選項默認顯示前10行 [root@62q ~]# head -n5 test # -n5表示查看前5行,也可以直接省略n,直接以-5的數字表示 1855 1855 794 3355 97(4)查看后n行:tail
[root@62q ~]# tail test [root@62q ~]# tail -n5 test 56 3657 466 466 56 [root@62q ~]# tail -n5 -f test # -f 查看文件尾部,不退出,等待顯示后續追加至此文件的新內容2.文本處理
(1)自定義查看文本:cut
[root@62q ~]# cut -d: -f1-3 /etc/passwd # -d表示分隔符,-f表示行號 root:x:0 bin:x:1 daemon:x:2 adm:x:3 lp:x:4 sync:x:5 shutdown:x:6(2)文本排序:sort
[root@62q ~]# sort test #按照ascii順序排序 1855 1855 1855 22356 3355 3657 [root@62q ~]# sort -n test # -n按照數值排序 56 56 97 466 [root@62q ~]# sort -r test # -r降序排序 97 794 56 56 466(3)刪除相鄰的重復行:uniq
[root@62q ~]# uniq test #刪除重復行(注意,只會刪除相鄰的重復行) 1855 794 3355 97 1855 3886 22356 56 3657 466 56 [root@62q ~]# uniq -c test # -c顯示重復的次數2 18551 7941 33551 971 18551 38861 223561 561 36572 4661 56 [root@62q ~]# uniq -d test -d只顯示重復行 1855 466(4)文本統計: wc
[root@62q ~]# wc test 13 13 57 test #分別為行數 單詞數 字節 [root@62q ~]# wc -l test # -l行數 13 test [root@62q ~]# wc -w test #-w 單詞數 13 test [root@62q ~]# wc -c test # -c字節數 57 test(5)字符處理命令,用于轉換或刪除字符:tr
[root@62q ~]# tr "a-z" "A-Z" < /etc/passwd #將passwd文本中的a-z字母轉換成A-Z ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH BIN:X:1:1:BIN:/BIN:/SBIN/NOLOGIN DAEMON:X:2:2:DAEMON:/SBIN:/SBIN/NOLOGIN ADM:X:3:4:ADM:/VAR/ADM:/SBIN/NOLOGIN LP:X:4:7:LP:/VAR/SPOOL/LPD:/SBIN/NOLOGIN SYNC:X:5:0:SYNC:/SBIN:/BIN/SYNC [root@62q ~]# tr -d "a-z" < /etc/passwd ##將passwd文本中的a-z全部刪除 ::0:0::/:// ::1:1::/:// ::2:2::/:// ::3:4:://:// ::4:7::///:// ::5:0::/://?
轉載于:https://www.cnblogs.com/pastman/p/4713821.html
總結
以上是生活随笔為你收集整理的centos文本查看及处理相关的常用命令的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: coredump调试的使用
- 下一篇: fgets和scanf的区别