【发布时间】:2018-03-14 11:07:07
【问题描述】:
我有一个包含 4 列的文件,由制表符分隔。在最后一列中,引号之间有时可能有尾随制表符。 这是与trim leading and trailing spaces from a string in awk 类似的问题。这是一个例子:
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>"
这是我目前想出的:
gawk --re-interval -F '"' 'NF = 9 {if ($8 ~ /\t$/) {gsub(/[\t]+$,"",$8)} ;}'
问题在于它破坏了我的格式,这意味着我没有为每一列添加引号。好消息是列之间的选项卡仍然存在:
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