grep (find text in files)

team bbl


Searches one or more files for text that matches regular expressions. The grep command is described in Chapter 7.

 Format:    grep pattern filelist Examples:  grep "^Table [0-9]:" * 

Displays each line that matches the regex. The filename and line number is listed.

Opt

What It Does

Example

-A n

Display n lines after the match

grep -A 3 Table *

-B

Display n lines before the match

grep -B 3 Table *

-c

Display only count of matched lines, not the text

grep -c Table *

-C

Display two lines before and after the matching line

grep -C include *

-i

Ignore case

grep -I Table report*

-r

Search files in subdirectories also

grep -r Table *

-v

Display lines that do not match

grep -v Error *

-w

Match whole words only

grep -w Table *.txt

-x

Match whole lines only

grep -x "This is a line" *


    team bbl



    Spring Into Linux
    Spring Into Linux
    ISBN: 0131853546
    EAN: 2147483647
    Year: 2005
    Pages: 362
    Authors: Janet Valade

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net