How to remove unwanted commas from a .csv file?

how to remove unwanted commas from a .csv file

Input file format

"Server1","server-PRI-Windows","PRI-VC01","Microsoft Windows Server 2012, (64-bit)","Powered On","1,696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"
"Server2","server-PRI-Windows","PRI-VC01","Microsoft Windows Server  2012, (64-bit)","Powered  On","2,696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"
"Server3","server-PRI-Windows","PRI-VC01","Microsoft Windows Server  2012, (64-bit)","Powered  On","3,696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"

Output required

"Server1","server-PRI-Windows","PRI-VC01","Microsoft Windows Server  2012(64-bit)","Powered  On","1696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"
"Server2","server-PRI-Windows","PRI-VC01","Microsoft Windows Server  2012(64-bit)","Powered  On","2696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"
"Server3","server-PRI-Windows","PRI-VC01","Microsoft Windows Server  2012(64-bit)","Powered  On","3696.12","server-GEN-SFCHT2-VMS-R013,server-GEN-SFCHT2-VMS-R031,server-GEN-SFCHT2-VMS-R023"

I have removed the comma from column 6 (Size of the Capacity)
I have removed the comma from column 4 (Os field)

how about:

awk -F'"' '{$12=substr($12,index($12,",")+1);sub(",","",$8)}1' OFS='"' myFile

Whenever you start a thread in the Shell Programming and Scripting forum, please tell us what operating system and shell you're using!

And give us a clear explanation of what it is that you want to do. The fields in your CSV file seem to be separated by three character <double-quote><comma><double-quote> sequences.

You say you want to remove unwanted <comma>s; but you don't explain why the <comma>s in field six are unwanted, why both a <comma> and a <space> are unwanted in field four, and you don't explain why the <comma>s in other fields are not unwanted. You didn't say anything in your description about removing unwanted <space>s. (Note that the script vgersh99 suggested doesn't produce the output you say you want because it didn't remove the <space> after the <comma> you said you wanted removed in field four.)

With well over 100 posts in this forum, you should know by now that we expect you to show us what you have tried to solve this problem on your own. We want to help you learn how to do things like this on your own; not act as your unpaid programming staff.

1 Like

I agree with Don - the proposed solution is somewhat limited in scope as it only deals with the provided sample data.
I makes (or rather doesn't consider more generic cases, e.g. embedded double quote and multi-line csv fields).
Removing a sampled (but not stated explicitly) trailing blank(s) is is easy to fix and could be left as an exercise for the OP.

In order consider most (all?) cases of the csv file parcing, one would need a heavier "fork lift" for sure....

Sorry i was using cygwin in windows. I was using this dont no this remove all comma from the csv file. But i cant awk but this resolve my issue

  sed '/[[:digit:]]/ {s/,//g}'
  

I don't quite understand the statement above....
Also, cygwin does have awk as part of the distribution....

You also haven't addressed any points that Don'd raised...

1 Like