shell特殊符號、cut命令、sort_wc_uniq命令、tee_tr_split命令、shell特殊符號下
shell特殊符號
* 任意個任意字符
[root@test ~]# ls *.txt
1.txt 23.txt 2.txt david.txt
? 任意一個字符
[root@test ~]# ls ?.txt
1.txt 2.txt
# 註釋字符
[root@test ~]# #echo ‘ok‘
\ 脫義字符
[root@test ~]# echo -e ‘123\n456\n789\t0000‘
123
456
789 0000
| 管道符
[root@test ~]# cat 2.txt|wc -l
2
cut命令
-b 指定第幾個字節
-d 分隔符
-f 指定段號
-c 指定第幾個字符;若是中文字符等於3個字節c=3b;英文c=b
[root@test ~]# cat 2.txt
I am linux my qq 1234567
[root@test ~]# cat 2.txt|cut -b 1,2,3,4
I am
[root@test ~]# cat 2.txt|cut -c 1,2,3,4
I am
中文的區別
[root@test ~]# cat 1.txt
我是 linux
[root@test ~]# cat 1.txt|cut -c 1
我
[root@test ~]# cat 1.txt|cut -b 1,2,3
我
例子2:打印出linux my
[root@test ~]# cat 2.txt
I am linux my qq 1234567
[root@test ~]# cat 2.txt|cut -d ‘ ‘ -f 3,4
linux my
sort_wc_uniq命令
-n 按照數值排序 升序
-r 倒序
-u 排除重復的行
[root@test ~]# sort -n 2.txt
0
0
0
1
1
2
2
3
4
45
56
56
66
87
687
-r:倒序
[root@test ~]# sort -r 2.txt
87
66
56
56
45
4
去重:
[root@test ~]# sort -un 2.txt
0
1
2
3
4
45
56
66
87
-t 表示以:為分隔符; -k3 表示以第3段排序
[root@test ~]# sort -n -t : -k3 3.txt
pear:90:2.3
apple:10:2.5
orange:20:3.4
banana:30:5.5
wc -l 統計文件行數
wc -c 統計字符數
wc -w 統計單詞數
uniq
uniq -d:僅顯示重復出現的行
uniq -u:顯示不重復出現的行
uniq -c:計算個數
[root@test ~]# cat test.log
https://www.taobao.com/1.html
https://www.taobao.com/2.html
https://www.taobao.com/3.html
https://www.taobao.com/2.html
https://www.baidu.com/inyydex.html
https://www.baidu.com/in.html
https://www.baidu.com/index.html
https://jusjuu.ia/jsw/zdnst/index.html
[root@test ~]# awk -F ‘[:/]+‘ ‘{print $2}‘ test.log |uniq
www.taobao.com
www.baidu.com
jusjuu.ia
[root@test ~]# awk -F ‘[:/]+‘ ‘{print $2}‘ test.log |uniq -c
4 www.taobao.com
3 www.baidu.com
1 jusjuu.ia
[root@test ~]# awk -F ‘[:/]+‘ ‘{print $2}‘ test.log |uniq -d
www.taobao.com
www.baidu.com
tee_tr_split命令
tree:
tee 和>類似,重定向的同時還在屏幕顯示
tr
替換字符
[root@test ~]# echo "HELLO WORLD" | tr ‘A-Z‘ ‘a-z‘
-d:刪除
[root@test ~]# echo "HELLO 123 WORLD12 12" | tr -d [0-9]
HELLO WORLD
[root@test ~]# echo "HELLO:123 WORLD:12 " | tr -s ":" "="
HELLO=123 WORLD=12
split
切割;
-b大小(默認單位字節)
-l行數
本文出自 “探索發現新事物” 博客,請務必保留此出處http://shenj.blog.51cto.com/5802843/1978798
shell特殊符號、cut命令、sort_wc_uniq命令、tee_tr_split命令、shell特殊符號下