在awk中从字符串/列修剪尾部制表符

在awk中从字符串/列修剪尾部制表符,awk,Awk,我有一个文件,其中包含由制表符分隔的4列。在最后一列中,引号之间有时会有尾随的制表符。 这是一个类似的问题。以下是一个例子: col1 col2 col3 col4 "12" "d" "5" "this is great" "13" "d" "6" "this is great<tab>" "14" "d" "7" "this is great<tab><tab>" "15" "d" "8" "this is great" "16" "d" "9" "this

我有一个文件,其中包含由制表符分隔的4列。在最后一列中,引号之间有时会有尾随的制表符。 这是一个类似的问题。以下是一个例子:

col1 col2 col3 col4
"12" "d" "5" "this is great"
"13" "d" "6" "this is great<tab>"
"14" "d" "7" "this is great<tab><tab>"
"15" "d" "8" "this is great"
"16" "d" "9" "this is great<tab>"
问题是它破坏了我的格式,这意味着我的每一列都没有引号。好的是,列之间的选项卡仍然存在:

col1 col2 col3 col4
12 d 5 this is great
13 d 6 this is great
14 d 7 this is great
15 d 8 this is great
16 d 9 this is great

我做错了什么?

您需要告诉awk,输出字段分隔符(OFS)也是一个引号。例如:

awk-vofs=''-F''NF==9{
如果($8~/\t$/){
gsub(/[\t]+$/,“”,$8)
}
}
1'input.txt
输出:

col1   col2   col3   col4
"12"   "d"    "5"    "this is great"
"13"   "d"    "6"    "this is great"
"14"   "d"    "7"    "this is great"
"15"   "d"    "8"    "this is great"
"16"   "d"    "9"    "this is great"

输出是否可能与输入不一致(列之间的间距)?我将其与OP的示例文件进行比较。否则+1用于解释问题所在;-)@克万托尔:所以不能正确地表示硬标签,所以我们必须适应
col1   col2   col3   col4
"12"   "d"    "5"    "this is great"
"13"   "d"    "6"    "this is great"
"14"   "d"    "7"    "this is great"
"15"   "d"    "8"    "this is great"
"16"   "d"    "9"    "this is great"