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}'
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"
Try:
grep -n -P "\t" $1 | awk --field-separator=":" '{$2=$2; print "["$1"]"$2}'
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' ' '
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.