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"
A single line sed command can remove quotes from start and end of the string. The above sed command execute two expressions against the variable value. The first expression 's/^"//' will remove the starting quote from the string. Second expression 's/"$//' will remove the ending quote from the string.
One use of an escape sequence is to include a double-quote character in a string constant. Because a plain double quote ends the string, you must use ' \" ' to represent an actual double-quote character as a part of the string. For example: $ awk 'BEGIN { print "He said \"hi!\
A simple and elegant answer from Stripping single and double quotes in a string using bash / standard Linux commands only: BAR=$(eval echo $BAR) strips quotes from BAR . If you don't want anything printed out, you can pipe the evals to /dev/null 2>&1 .
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With