grep "string" file_name
grep "string" file_name_* ---multiple files
grep -i "string" file_name ---ignore sensitive case
grep -w "word" file_name ---search only word matched
grep -n "string" file_name --display the line
grep -A N "string" file_name -- search string and print N lines after matched lines
grep -B N "string" file_name -- search string and print N lines before matched lines
regular expression
grep "lines.*empty" demo_file
From documentation of grep: A regular expression may be followed by one of several repetition operators:
-
? The preceding item is optional and matched at most once.
-
* The preceding item will be matched zero or more times.
-
+ The preceding item will be matched one or more times.
-
{n} The preceding item is matched exactly n times.
-
{n,} The preceding item is matched n or more times.
-
{,m} The preceding item is matched at most m times.
-
{n,m} The preceding item is matched at least n times, but not more than m times
阅读(364) | 评论(0) | 转发(0) |