Saturday, August 2, 2008

Print lines with more than two occurrence of a pattern using sed, awk, grep


Input file:

$
cat myfile.txt
"AA "345" SDF"
"BB DERT"
CC"123" "DERA
"12"DD"TYU
ASD""123

Output required:
Print only lines which contain more than two " (double quote)
i.e.

"AA "345" SDF"
CC"123" "DERA
"12"DD"TYU

There are a number of ways to do this:

$ grep '".*".*"' myfile.txt

$ awk -F'"' 'NF>=4' myfile.txt

$ awk '/".*".*"/' myfile.txt

$ sed -n '/".*".*"/'p myfile.txt

$ sed -n '/\("\).*\1.*\1/p' myfile.txt

1 comment:

Anirudh said...

sed -e 's/"/&/3;t' -e 'd'

© Jadu Saikia www.UNIXCL.com