linux命令之排序sort、统计wc、截取字符串cut

排序命令:sort

sort /etc/passwd  按照行首a-z顺序排
sort -r /etc/passwd  按照行首z-a顺序排
sort -t ":" -k 3,3 /etc/passwd  以冒号分割,以第三个字段开头,第三个字段结尾排序,即只使用第三个字段排序

统计命令:wc

[root@localhost tmp]# wc /etc/passwd
25 35 1127 /etc/passwd
25行 35单词 1127字符

选项:-l: 只统计行数;  -w:   只统计单词数;  -m:   只统计字符数

截取字符串命令:cut

cut -f n    提取第n列。

cut -d ":"  以冒号分割

[root@localhost 11]# cat student2.txt
#!/bin/bash
ID Name gender mark
1 sl M 89
2 hus M 90
3 sd M 99
提取第二列:
[root@localhost tmp]# cut
-f 2 student2.txt #!/bin/bash Name sl hus sd
提取第二、三列:
[root@localhost
11]# cut -f 2,3 student2.txt #!/bin/bash Name gender sl M hus M sd M
取出/etc/passwd 中添加的普通用户
[root@localhost 11]# cat /etc/passwd | grep /bin/bash | grep -v root | cut -d":" -f 1
oracle
esuser
sl

grep -v :排除
cut -d ":" :用冒号分割

 

posted @ 2019-07-09 08:19  雷雨客  阅读(123)  评论(0编辑  收藏  举报