Searching for Pattern

grep ­ scans its input for a pattern, displays the line containing that pattern
     usage: grep options pattern filename(s)

searching for a text string in one
     grep 'boss' /etc/passwd
     searches for the pattern boss in the /etc/passwd file

searching for a text string in multiple files
     grep  ‘root’ *.txt

Case­insensitive file searching with the Unix grep command
     grep ­i ‘hello’ hello.txt

 Reversing the meaning of a grep search
     grep ­v ‘boss’ /etc/passwd
     Displays all the lines that do not contain the specified pattern
Using grep in a Unix/Linux command pipeline
    ls ­al | grep ‘^d’
    print the lines that starts with d

Linux grep command to search for multiple patterns at one time
    egrep ‘boss|root’ /etc/passwd

grep pattern matching and regular expressions (regex patterns)
     grep '[FG]oo' *
     grep '[0­9][0­9][0­9]' *
     grep '^fred' /etc/passwd

Comments

Popular Posts