1)$ grep -n '^south' datafile
3:southwest SW Lewis Dalsass 2.7
2)$ grep -i 'pat' datafile
Pat Huang yuanxiao
ps: The -i option turns off case sensitivity (nomatter lowercase or uppercase ).
3)$grep -v 'Li' datefile
ps:The -v option prints all lines not contain the pattern 'Li'.
4)$grep -l 'SE' *
ps: The -l option only prints the filenames where the pattern is found.
5)$grep -c 'west' datafile
ps:The -c option causes grep to print how much lines which
matches the pattern .(but if the pattern matches three times in a line, it
only count one time)
6)$grep -w 'north' datafile
ps:The -w option causes grep to find the pattern only if it is a word, not
part of word. only the line contain the word north is printed, not
northwest.
summary:grep can used combine with regular expression, so it's a powerful
tool of unix.
grep [-v] [-l] [-w] [-c] [-] [] [] [] [] [ ]
博客介绍了grep命令在Unix中的多种用法,如使用 -n 显示匹配行号、-i 忽略大小写、-v 排除匹配行等。还提到grep可与正则表达式结合,是Unix中强大的工具。
1078

被折叠的 条评论
为什么被折叠?



