天天看点

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

中文的区别

[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|cut -d ' ' -f 3,4

linux my

sort_wc_uniq命令

-n 按照数值排序 升序

-r  倒序

-u 排除重复的行

[root@test ~]# sort -n 2.txt

1

3

4

45

56

66

87

687

-r:倒序

[root@test ~]# sort -r 2.txt

去重:

[root@test ~]# sort -un 2.txt

-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.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

<a href="http://www.baidu.com/" target="_blank">www.baidu.com</a>

tee_tr_split命令

tree:

tee 和&gt;类似,重定向的同时还在屏幕显示

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行数

本文转自 jiekegz  51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1978798

继续阅读