Desired Output:
[3] print(Hi, How are you?)
[5] print(I'm good, how are you?)
But Output I'm getting:
[3] print(Hi, How are you?)
[5] print(I'm good, how are you?)
Command Im using:
grep -n -P "\t" $1 | awk --field-separator=":" '{print "["$1"]"$2}'
CodePudding user response:
You never need grep when you're using awk and using :
as the field separator then printing $2
and would truncate lines like print(I'm good: I got paid)
to print(I'm good
so don't do that.
You didn't provide sample input so it's a guess at what you want to do based on reading the code you provided that doesn't do what you want to do so YMMV but this may be what you want:
awk 'sub(/\t/,""){print "["NR"]", $0}' "$1"
CodePudding user response:
Try:
grep -n -P "\t" $1 | awk --field-separator=":" '{$2=$2; print "["$1"]"$2}'
CodePudding user response:
If you want to replace every tab (\t
) with space (
) then considering that you applied linux
tag, you might use tr
command like so
grep -n -P "\t" $1 | awk --field-separator=":" '{print "["$1"]"$2}' | tr '\t' ' '