ysrini
November 6, 2012, 3:06pm
1
Hi, I want to print the first column with original value and without any double quotes
The output should look like
<original column>|<column without quotes>
$ cat a.txt
"20121023","19301229712","100397"
"20121023","19361629712","100778"
"20121030A","19361630412","100838"
20121030","19361630412","100915"
$ awk -F',' '{fln1=gsub(/\"/,"") $1; print $1"|"fln1}' a.txt
20121023|620121023
20121023|620121023
20121030A|620121030A
20121030|520121030
Why am I getting '6' and '5' in the replaced column values?
Thanks,
-sri
rdrtx1
November 6, 2012, 3:19pm
2
try:
awk -F',' '{f=$1; gsub("\"","",f);print $1"|"f}' a.txt
ysrini
November 6, 2012, 3:42pm
3
Thanks rdrtx1,
i want to store the result of gsub in a variable that i have to further use later within the awk line
When i stored the gsub result in Y, it displays only the first character
$ awk -F',' '{f=$1; Y=gsub("\"","",f);print $1"|"f"|"Y}' a.txt
"20121023"|20121023|2
"20121023"|20121023|2
"20121030A"|20121030A|2
20121030"|20121030|1
rdrtx1
November 6, 2012, 3:46pm
4
gsub returns the number of matches. In the example, the unquoted result is stored in variable f.