Professional Documents
Culture Documents
Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the
filenames.(for multiple file)
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple
times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
with each such part on a separate output line.
$grep -i "ahmedanad" a
2. Inverting the pattern match : You can display the lines that are not
matched with the specified search string pattern using the -v option.
$ grep -v rahul a
$grep -c ahmedabad a
$ grep -w SURAT a
$ grep -n maan a
$grep -l "ahmedabad" *
or
Cat name
rahul
shiv
riya
kushi
maan
grep –f name a
$ grep "^100" a
10. Matching the lines that end with a string : The $ regular
expression pattern specifies the end of a line. This can be
used in grep to match the lines which end with the given
string or pattern.
$ grep “Ahmedabad$” a
12. extened grep we can use egrep command for the multiple
keyword search
$egrep e “riya|maan|Rahul”
13. find file from multiple file and folder
$ls | grep a
Echo {aaa,bbb,ccc,ddd}
Echo {a..z}
Echo {1..9}
Echo a{0..9}b
Command substitution
$alias datels=`date;ls`
$alias datels
$unalias datels
Echo \<hello
Echo \?hello
Echo <unix><is><good>
Echo \<unix\>\<is\>\<good\>
Echo ‘<unix><is><good>’
Var = yourname
pr filename
pr –n filename (index)
pr -3 filename (column)
Translate characters.
tr [a-z][A-Z] enter the data and enter (ctrl+c and ctrl+d for
exit)
tr [:lower:][:upper:] < a
sort filename
uniq filename