Linux pipe
管道符:|
作用:合并多个命令达到组合效果
cut:分割文件,只能取出一列
Example 1:将passwd文件中的用户名分割到passwd.username
more passwd|cut -d: -f1 > passwd.username
Example 2:将passwd文件中的第一到四个字符分割到passwd.username
more passwd|cut -c4-8 > passwd.username
sort:排序
默认为按字母排序;
-n 数字排序;
-u remove duplication;
-r reversed order;
-f ignore case of characters
-k sort by which field1
-t<x> user x as field separator
Example 1:将passwd文件中的uid分割出来,并排序
more passwd|cut -d: f3|sort -n > passwd.uid
Example 2: sort the passwd file following the column three by numerical order
sort -t: -k3 -n /etc/passwd
uniq:分类统计
例如:将passwd文件中按照bash类型分类统计
more passwd|cut -d: -f7|sort|uniq -c
tee:保存中间文件
例如:将passwd文件中分割出bash类型列到passwd.bash,再按照bash类型分类统计
more passwd|cut -d: -f7|tee passwd.bash|sort|uniq -c
paste:按列合并文件
例如:合并passwd.username和passwd.bash,以;来间隔
paste passwd.username passwd.bash -d: > passwd.paste
xargs: converts input to argument list
Example:
1. make one file a.txt with context below
b.txt
c.txt
d.txt
2. create b.txt,c.txt,d.txt in the same folder
3. cat a.txt|xargs rm -f
then the b.txt,c.txt,d.txt will be deleted
Comments
Post a Comment