grep用于查找字符串
比如有一个用户名为whuang,那么我如何获取他的家目录呢?
grep "^whuang:" /etc/passwd |awk -F : {‘print $6‘}
grep "^whuang:" /etc/passwd |awk -F : {‘print $3‘}
grep "^whuang:" /etc/passwd |awk -F : {‘print $4‘}
grep "^whuang:" /etc/passwd |awk -F : {‘print $4‘}|xargs -i grep {} /etc/group|awk -F : {‘print $1‘}
whuang
netstat -anp |grep "^[a-z]\+[ ]\+0[ ]\+0[ ]\+[0-9\.]\+:80[ ]\+"|awk -F" " {‘print $7‘}|cut -d"/" -f1
grep ‘like‘ test.c(在文件test.c中搜索包含“like”的行)
grep -n ‘like‘ test.c(输出行号)
[root@localhost awk-study]# grep -n ‘like‘ test.c
3:I like java hw.txt
注意:使用+表示多个时,一定要在+前加上转义字符
原文地址:http://blog.csdn.net/hw1287789687/article/details/45276877