$ grep ::Gloabally Search a Regular expression and print it.
This command is used to search a particular pattern(single string ) in a file or directory and regualr expression(pattern which uses wild card characters).
syntax - $grep pattern filename
eg. $grep dwhlabs dwh (It displays all the lines in a file which as dwhlabs pattern/string) - Character Pattern
eg. $grep "dwhlabs website" dwh - character pattern
eg. $grep \< dwhlabs\> dwh (It displays all the line in a file which as a exact word 'dwhlabs') - Word Pattern
eg. $grep ^UNIX$ language (It displays all the lines in the file which has a single word 'UNIX' ) - Line Pattern
$grep options
$grep -i pattern filename (ignore case sensitive)
$grep -c pattern filename (It displays total count of lines)
$grep -n pattern filename (It displays along with the line number)
$grep -l pattern filename (It displays filename in the current directory)
$grep -v pattern filename (It displays unmatched pattern lines)
Question ?
Q)How to remove blank lines in a file?
A)$grep -v "^$" file1>tmp | mv tmp>file1
Explanation :: Piping concept is used to combine more than one cammand.Here we first identifing the non blank files in file1 and redirecting the result to tmp (temporary file).This temporary file is input to the next command. Now we are renaming the tmp into file1.Now check the file1 result <You will not find any blank lines>
fgrep ::
This command is used to search multiple strings or one string but not regular expression.
syntax - $fgrep "pattern1
>pattern2
>....
>patternn " filename
eg.$fgrep "unix
>c++
>Data Warehouse" stud
egrep :: Extended grep
This command is used to search for single or multiple patterns and also regular expressions.
|