I have a sample file like below. There are leading whitespaces. Is there a way to detect them and print the exact line number which contains the whitespace using a shell script?
test space at back
test space at front
TAB at end
TAB at front
You can use something like this:
awk '/^[ \t]+/ {printf NR ", "}' test.txt
The above command will print the line numbers which have leading space(s) or tab(s) of the file test.txt
A version which would use the same regular expression as the one supplied by Farahmand but using grep
instead of awk
could look like this:
grep -n -E $'^[ \t]+' test.txt
The $
is necessary to escape/interpret the \t
.
grep
in some way I think.