Hi Guys,
Need help with logic to break Column nth in a CSV file into two
for e.g
Refer below the second column as the nth column
"abcd","[/place/asia/india/mumbai,/product/sw/tomcat]","type/beta-version"
need output in a following format
"abcd","/place/asia/india/mumbai","/product/sw/tomcat","type/beta-version"
any help is greatly appreciated.
thanks in advance
pamu
September 6, 2013, 6:21am
2
Hope this helps you
awk -F, '{ for(i=1;i<=NF;i++){
if($i ~ /^\"/ && $i !~ /\"$/){$i=$i"\""}
if($i ~ /\"$/ && $i !~ /^\"/){$i="\""$i}S=S?S FS $i : $i}
gsub(/[][]/,"",S)
print S;S=""}' file
thank a ton for such a quick reply
its definitely working for the above e.g ,wanted to implement this for large dataset and restrict this parsing to apply on particular column, say column 16.
can you please drop a hint.
thanks in advance
pamu
September 6, 2013, 7:08am
4
for 16th column only
try
awk -F, '{if($16 ~ /^\"/ && $16 !~ /\"$/){$16=$16"\""}
if($16 ~ /\"$/ && $16 !~ /^\"/){$16="\""$16}
gsub(/[][]/,"",$16)}1' file
for some reason this is not working..
pamu
September 10, 2013, 6:40am
6
Corrected my previous post. Please check.