identifying leading line space - shell script

120 views Asked by At

I have a sample file like below. There are leading line spaces. Is there a way to detect them and print the exact line number which contains the line space using shell script?

test space at back 
 test space at front
TAB at end  
    TAB at front
2

There are 2 answers

0
AudioBubble On

This works for me ! if grep -n '^ ' config.js /dev/null >&2; then echo "$0: Leading spaces identified above; aborting" >&2 exit 1 fi

0
Samuel Kirschner On

grep can find blanks with [:blank:] and the beginning of a line with ^ (regex)

grep -n will print the line number

try grep -n '^[[:blank:]]' filename