Bash – Remove nth character from middle of string using Shell

bashsed

I've been searching google for ever, and I cannot find an example of how to do this. I also do not grasp the concept of how to construct a regular expression for SED, so I was hoping someone could explain this to me.

I'm running a bash script against a file full of lines of text that look like this: 2222,H,73.82,04,07,2012

and I need to make them all look like this: 2222,H,73.82,04072012

I need to remove the last two commas, which are the 16th and 19th characters in the line.
Can someone tell me how to do that? I was going to use colrm, which is blessedly simple, but i can't seem to get that installed in CYGWIN. Please and thank you!

Best Solution

I'd use awk for this:

awk -F',' -v OFS=',' '{ print $1, $2, $3, $4$5$6 }' inputfile

This takes a CSV file and prints the first, second and third fields, each followed by the output field separator (",") and then the fourth, fifth and sixth fields concatenated.

Personally I find this easier to read and maintain than regular expression-based solutions in sed and it will cope well if any of your columns get wider (or narrower!).