gpt4 book ai didi

regex - 删除 awk 命令中的引号

转载 作者:行者123 更新时间:2023-12-03 11:46:08 24 4
gpt4 key购买 nike

我有一个需要使用 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"

最佳答案

您可以使用 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"

关于regex - 删除 awk 命令中的引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19474860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com