[英]How to remove the tabs from the output while using grep command in bash?
所需的 Output:
[3] print(Hi, How are you?)
[5] print(I'm good, how are you?)
但是 Output 我得到了:
[3] print(Hi, How are you?)
[5] print(I'm good, how are you?)
我使用的命令:
grep -n -P "\t" $1 | awk --field-separator=":" '{print "["$1"]"$2}'
當您使用 awk 並使用:
作為字段分隔符然后打印$2
並且會截斷諸如print(I'm good: I got paid)
之類的行以print(I'm good
,所以不要那樣做)時,您永遠不需要 grep。
您沒有提供示例輸入,因此根據閱讀您提供的代碼來猜測您想要做什么,而這些代碼並沒有做您想做的事情,所以 YMMV 但這可能是您想要的:
awk 'sub(/\t/,""){print "["NR"]", $0}' "$1"
嘗試:
grep -n -P "\t" $1 | awk --field-separator=":" '{$2=$2; print "["$1"]"$2}'
如果您想用空格替換每個制表符 ( \t
) (
) 然后考慮到您應用linux
標記,您可以像這樣使用tr
命令
grep -n -P "\t" $1 | awk --field-separator=":" '{print "["$1"]"$2}' | tr '\t' ' '
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.