Linux常用命令-文本统计

2020-07-16  本文已影响0人  是立品啊

head

head /etc/passwd
head -n 3 /etc/passwd 查看前3行
head -c 10 /etc/passwd 查看前10个字节

tail

tail /etc/passwd
tail -1000 /etc/passwd 查看尾部1000行

综合:获取3-12行

head -12 /etc/passwd | tail -10 #先获取前12行,再从前12行中获取后10行

cut

cut -d ":" -f 1,3 /etc/passwd # 按:分割,取出分割后的第1,3列
cut -d" " -f2 test.log #按空格分割,取出第2列

uniq

sort

 head -50 testcases.log | cut -d " " -f4 | sort | uniq #日志文件前50行 取出第四列用户名,排序后去掉重复的用户名
 head -50 testcases.log | cut -d " " -f4 | sort | uniq -c  #日志文件前50行 取出第四列用户名,排序后去掉重复的用户名,查看每个user的出现的次数

wc(world count)

wc -l testcases.log  #打印文件的行数
上一篇 下一篇

猜你喜欢

热点阅读