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"
CC"123" "DERA

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

"AA "345" SDF"
CC"123" "DERA

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