您的位置:首页 > 运维架构 > Shell

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

2017-11-03 17:01 886 查看
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,4I 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行数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 基础
相关文章推荐