regex 删除awk命令中的引号

wn9m85ua  于 2023-08-08  发布在  其他
关注(0)|答案(2)|浏览(102)

我有一个文本文件需要使用awk处理。

"5","1211274723","0","D","2"
"1","1211292921","0","A","2"
"5","1211295793","0","A","2"
"5","1211310146","0","A","2"
"5","1211310310","0","A","2"
"4","1211315271","0","A","2"
"5","1211318203","0","D","2"
"2","1211323658","0","A","2"
"5","1211329224","0","A","2"
"5","1211330064","0","A","2"

# cat testme.csv | awk -F',' '{print "set", $2, $3}'
set "1211274723" "0"
set "1211292921" "0"
set "1211295793" "0"
set "1211310146" "0"
set "1211310310" "0"
set "1211315271" "0"
set "1211318203" "0"
set "1211323658" "0"
set "1211329224" "0"
set "1211330064" "0"

字符串
唯一的问题是,我不知道如何删除电话号码周围的引号。所以我的最终输出看起来像这样…

set 1211274723 "0"
set 1211292921 "0"
set 1211295793 "0"
set 1211310146 "0"
set 1211310310 "0"
set 1211315271 "0"
set 1211318203 "0"
set 1211323658 "0"
set 1211329224 "0"
set 1211330064 "0"

3phpmpom

3phpmpom1#

你可以使用gsub函数:

awk -F',' '{gsub(/"/, "", $2); print "set", $2, $3}' testme.csv 
set 1211274723 "0"
set 1211292921 "0"
set 1211295793 "0"
set 1211310146 "0"
set 1211310310 "0"
set 1211315271 "0"
set 1211318203 "0"
set 1211323658 "0"
set 1211329224 "0"
set 1211330064 "0"

字符串

de90aj5v

de90aj5v2#

使用双引号作为字段分隔符;

awk -F'"' '{print "set", $4, "\""$6"\""}' testme.csv

字符串

相关问题