'How to remove the tabs from the output while using grep command in bash?
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}'
Solution 1:[1]
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"
Solution 2:[2]
Try:
grep -n -P "\t" $1 | awk --field-separator=":" '{$2=$2; print "["$1"]"$2}'
Solution 3:[3]
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' ' '
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Frankfurters |
| Solution 3 | Daweo |
