Reputation: 157
I am trying to find the occurance of tab in a file some_file and print those line with leading line number. grep -nP "\t" some_file works well for me but I want sed or awk equivalent command for the same.
Upvotes: 2
Views: 522
Reputation: 17120
Well, you can always do it in sed:
cat -n test.txt | sed -n "/\t/p"
Unfortunately, sed can only print line numbers to stdout with a new line, so in any case, more than one command is necessary. A more lengthy (unnecessary so) version of the above, but one only using sed, would be:
sed = test.txt | sed -n "N;s/\n/ /;/\t/p"
but I like the one with cat
more. CATS ARE NICE.
Upvotes: 2
Reputation: 54532
To emulate: grep -nP "\t" file.txt
Here's one way using GNU awk
:
awk '/\t/ { print NR ":" $0 }' file.txt
Here's one way using GNU sed
:
< file.txt sed -n '/\t/{ =;p }' | sed '{ N;s/\n/:/ }'
Upvotes: 3