How to find lines that contain more than a single whitespace between strings in unix? How to find lines that contain more than a single whitespace between strings in unix? unix unix

How to find lines that contain more than a single whitespace between strings in unix?


grep '[[:space:]]\{2,\}' ${dname}.txt >> ${dname}_error.txt

If you want to catch 2 or more whitespaces.


Just this will do:

grep "  " ${dname}.txt >> ${dname}_error.txt

The two spaces in a quoted string work fine. The -E turns the pattern into an extended regular expression, which makes this needlessly complicated here.


below are the four ways.

pearl.268> sed -n 's/  /&/p' ${dname}.txt >> ${dname}_error.txtpearl.269> awk '$0~/  /{print $0}' ${dname}.txt >> ${dname}_error.txtpearl.270> grep '  ' ${dname}.txt >> ${dname}_error.txtpearl.271> perl -ne '/  / && print' ${dname}.txt >> ${dname}_error.txt