当前位置:网站首页>Grep of three swordsmen in text processing

Grep of three swordsmen in text processing

2022-07-07 12:57:00 LC181119

grep:Global search REgular expression and Print out the line

effect : Text search tools , According to the user specified “ Pattern ” Match the target text line by line ; Print the matched lines

Pattern : Filter conditions written by regular expression characters and text characters

Format :

grep [OPTIONS] PATTERN [FILE...]

Common options :

  • -color=auto         Color the matched text
  • -m #        matching # Stop after
  • -V           Display not pattern Matched rows , Take the opposite
  • -i            Ignore character case
  • -n           Display the matched line number
  • -c           Count the number of rows matched
  • -o           Show only strings that match
  • -q           silent mode , Do not output any information
  • -A #          after, after # That's ok
  • -B #          before, front # That's ok
  • -C #          context, Before and after # That's ok
  • -e           Implement logic between multiple options or Relationship , Such as grep -e ‘cat’ -e ‘dog’ file
  • -w           Match the whole word
  • -E          Use ERE, amount to egrep
  • -F           Regular expressions are not supported , amount to fgrep
  • -f file       Process according to the schema file
  • -r           Recursive directory , But don't handle soft links
  • -R          Recursive directory , But dealing with soft links

Example : Take the same line of two files

[19:33:09 [email protected] data]#cat f1.txt 
a
b
1
c
[19:33:24 [email protected] data]#cat f2.txt 
b
e
f
c
1
2
[19:33:28 [email protected] data]#grep -f f1.txt f2.txt 
b
c

原网站

版权声明
本文为[LC181119]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130616434247.html