简体   繁体   中英

Remove quotes in awk command

I have a text file that needs to be processed using 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"

The only problem is that I do not know how to remove the quotes around phone numbers. So that my final output will look something like this...

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"

You can use gsub function:

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"

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM