linux grep命令/tmp/sharetab.$$?[ x$fstype ! xnfs ] &&?echo $path\t$res\t$fstype\t$opts\t$desc
linux grep命令
>/tmp/sharetab.$$?
[ "x$fstype" != xnfs ] &&?
echo "$path\t$res\t$fstype\t$opts\t$desc"?
>>/tmp/sharetab.$$?
/usr/bin/touch -r /etc/dfs/sharetab /tmp/sharetab.$$?
/usr/bin/mv -f /tmp/sharetab.$$ /etc/dfs/sharetab?
if [ -f /etc/dfs/dfstab ] && /usr/bin/egrep -v '^[ ]*(#|$)'?
if [ $startnfsd -eq 0 -a -f /etc/rmwhile [ $wtime -gt 0 ]; do?
wtime=`expr $wtime - 1`?
if [ $wtime -eq 0 ]; then?
echo "Usage: $0 { start | stop }"?
# more size.txt?
the test file?
their are files?
The end?
# grep 'the' size.txt?
the test file?
their are files?
# grep '\<the' size.txt?
the test file?
their are files?
# grep 'the\>' size.txt?
the test file?
# grep '\<the\>' size.txt?
the test file?
# grep '\<[Tt]he\>' size.txt?
the test file
==================================================================
1,简介
使用正则表达式的一个多用途文本搜索工具.这个
(2)行匹配:输出匹配行的计数
? ? grep -c "48" data.doc? ?#输出文档中含有48字符的行数
(3)显示匹配行和行数
? ? grep -n "48" data.doc? ?? ? #显示所有匹配48的行和行号
(4)显示非匹配的行
? ? grep -vn "48" data.doc? ?? ?#输出所有不包含48的行
(4)显示非匹配的行
? ? grep -vn "48" data.doc? ?? ?#输出所有不包含48的行
(5)大小写敏感
? ? grep -i "ab" data.doc? ?? ? #输出所有含有ab或Ab的字符串的行
4, 正则表达式的应用
(1)正则表达式的应用 (注意:最好把正则表达式用单引号括起来)
? ? grep '[239].' data.doc? ?? ?#输出所有含有以2,3或9开头的,并且是两个数字的行
(2)不匹配测试
? ? grep '^[^48]' data.doc? ?? ?#不匹配行首是48的行
(3)使用扩展模式匹配
? ? grep -E '219|216' data.doc
(4) ...
? ? 这需要在实践中不断应用和总结,熟练掌握正则表达式。
5, 使用类名
可以使用国际模式匹配的类名:
[[:upper:]]? ?[A-Z]
[[:lower:]]? ?[a-z]
[[:digit:]]? ?[0-9]
[[:alnum:]]? ?[0-9a-zA-Z]
[[:space:]]? ?空格或tab
[[:alpha:]]? ?[a-zA-Z]
(1)使用
? ? grep '5[[:upper:]][[:upper:]]' data.doc? ???#查询以5开头以两个大写字母结尾的行