shell特殊符號、cut命令、sort_wc_uniq命令、tee_tr_split命令、shell特殊符號下

shell特殊符號

cut命令(截取列)linux

-d 指定分隔符 -f 指定截取列shell

[root@glinux-01 ~]# cat /etc/passwd|head -10|cut -d ":" -f 1,2
root:x
bin:x
daemon:x
adm:x
lp:x
sync:x
shutdown:x
halt:x
mail:x
operator:x

 -c 指定第幾個字符spa

[root@glinux-01 ~]# cat /etc/passwd|head -3|cut -c 2
o
i
a

sort_wc_uniq命令code

  • sort 排序(不加選項按數字,字母順序排序)
[root@glinux-01 ~]# cat 1.txt|sort 
1
2
3
a
b
c

 -n 按數字順序排序,字母比數字小排序

[root@glinux-01 ~]# cat 1.txt|sort -n
a
b
c
1
2

 -r反向排序it

[root@glinux-01 ~]# cat 1.txt|sort -nr
3
2
1
c
b
a
  • wc 統計命令 (-l 統計行數 -m統計字符數 -w統計詞)

wc 1.txt  2行數 2詞數 8字符數(換行符也算)test

[root@g_linux01 ~]# cat -A 1.txt
123$
abc$
[root@g_linux01 ~]# wc 1.txt
2 2 8 1.txt
  • uniq 去重複命令(只能夠按順序去重,所以多和sort 搭配使用)
[root@g_linux01 ~]# cat 1.txt
123
abc
123
1
1
[root@g_linux01 ~]# uniq 1.txt  
123             //123沒去重      
abc
123
1               //1去重了

 先排序,再去重-c 重複計數file

[root@g_linux01 ~]# sort -n 1.txt|uniq -c
      1 abc
      2 1
      2 123

tee_tr_split命令im

  • tee 重定向到文件中,並打印到屏幕上(-a 追加的文件中 >重定向不打印)
[root@g_linux01 ~]# sort -n 1.txt|uniq -c|tee a.txt
      1 abc
      2 1
      2 123
[root@g_linux01 ~]# cat a.txt
      1 abc
      2 1
      2 123
[root@g_linux01 ~]# sort -n 1.txt|uniq -c|tee -a a.txt
      1 abc
      2 1
      2 123
[root@g_linux01 ~]# cat a.txt
      1 abc
      2 1
      2 123
      1 abc
      2 1
      2 123
  • tr替換命令
[root@g_linux01 ~]# echo 'helloworld'|tr 'h' 'H'
Helloworld
[root@g_linux01 ~]# echo 'helloworld'|tr '[a-z]' '[A-Z]'
HELLOWORLD
  • split 切割命令(-b 指定切割大小 -l 指定切割行數)

split -b 100M 【filename】將文件按100M每一個切割統計

指定切割後的文件名

-l 1000 指定文件按1000行每一個切割

shell特殊符號下

>重定向 >>追加劇定向 2>錯誤重定向 2>>錯誤追加劇定向 &>正確錯誤重定向

|| 邏輯

命令1 || 命令2 命令1執行成功,則不執行命令2

例:[ -d test ] || mkdir test 判讀test是否存在,是不是目錄,若是不是則建立test目錄

&&邏輯與

命令1 && 命令2 命令1成功,則執行命令2

相關文章
相關標籤/搜索