Linux中的分析文本工具wc,sort,uniq等

wc命令:收集文本统计数据

常规选项 作用
-l 只计数行数
[root@centos8 ~ ]#wc -l test
23 test
[root@centos8 ~ ]#cat -n test
     1	aaaaaaaaaa
     2	dasfsa
     3	adsfsaw
     4	sfafsss
     5	asdffsa
     6	fdsgfxz
     7	agxzs
     8	8
     9	9
    10	10
    11	11
    12	
    13	
    14	
    15	
    16	
    17	
    18	
    19	
    20	
    21	aaaaaaaaaaaaaaa
    22	dddddddddd
    23	ddddddddddd

常规选项 作用
-w 只计数单词总数
[root@centos8 ~ ]#wc -w test
14 test
常规选项 作用
-c 只计数字节总数
[root@centos8 ~ ]#wc -c test
114 test
[root@cent
常规选项 作用
-m 只计数字符总数
-L 显示文件中最长行的长度

sort命令:文本排序
sort [option] files
默认排序

[root@centos8 ~ ]#cat /data/num
1
13
2
3
5
7
8
9
22 
88
1000
55
233
a
b
g
f
e

[root@centos8 ~ ]#sort /data/num

1
1000
13
2
22 
233
3
5
55
7
8
88
9
a
b
e
f
g

[root@centos8 ~ ]#sort /data/test /data/all.log 
a 
a b
 a b c
bin
boot
centos8.magedu.org
data
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
选项 作用
-r 执行反方向整理
-n 执行按数字大小整理
[root@centos8 ~ ]#cut -d: -f3 /etc/passwd | sort -n | head -n3
0
1
2
[root@centos8 ~ ]#cut -d: -f3 /etc/passwd | sort -nr | head -n3
65534
2002
1100
选项 作用
-t C 使用C选项做字段界定符
-k # 选项按照C字符分隔的#列来整理
[root@centos8 ~ ]#cut -d: -f1,3 /etc/passwd | sort  -t: -k2 -n
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12
ftp:14
apache:48
tss:59
sshd:74
dbus:81
postfix:89
systemd-resolve:193
rngd:995
sssd:996
unbound:997
polkitd:998
systemd-coredump:999
guan:1000
test:1001
gentoo:1002
nginx:1003
varnish:1004
tomcat:1006
git:1007
test2:1008
mageia:1100
slackware:2002
nobody:65534

uniq命令:去重
-c:显示重复的次数
-d:仅显示重复过的行
-u:仅显示不重复过的行

猜你喜欢

转载自blog.csdn.net/weixin_50904580/article/details/109285398