Linux text retrieval grep command notes

  Grep result information is retrieved on-line text very useful tool in linux system, by matching the command to be output to the terminal console.

  Syntax: grep [-ivnc] 'you need to match the contents' file name

  Common parameters:

  When -i search not case sensitive

  To match the number of rows retrieved -c

  -n retrieved explicit match line specific line number

  The results -v reverse matching is not included matches retrieved

  Ready to work:

  Create a text file test.txt test demo

  vim test.txt

  Insert the following:

  today IS Saturday

  tommow is Sumday

  my name is xiaoming

  Today

  Command examples:

  grep 'today' test.txt # test.txt file find the line that contains today's

  Output result: today IS Saturday

  grep -i 'today' test.txt # test.txt file find the line that contains today are not case sensitive

  Output:

  today IS Saturday

  Today Wuxi men and hospital Which http://www.zzch120.com/

  grep -in 'today' test.txt

  # Test.txt file find the line containing today is not case-sensitive contain line numbers

  Output:

  1:today IS Saturday

  4:Today

  grep -ci 'today' test.txt # test.txt file containing the running script found today are not case sensitive

  Output: 2

  grep -vn 'today' test.txt # running script to explicit test.txt file does not contain the line number of today

  Output:

  tommow is Sumday

  my name is xiaoming

  Note: cat pipe symbol rewrite command +

  such as:

  grep -ni 'today' test.txt

  It can be rewritten as:

  cat test.txt | grep -ni 'today'

Guess you like

Origin www.cnblogs.com/djw12333/p/10930408.html