Ok, so I've got a .csv file which was generated from an Excel document. It looks like this:
Now, unfortunately this is not exactly the format I want it in. The second and third fields seem to have a leading and trailing space, on ALMOST every line, which I want to remove. In addition, I want to add a number as the first field. So, the corrected line will look like this:Code:"field1"," field2 "," field3 "
Now I know there's probably a million and one ways to do this. I was trying to fix this up in a hurry so I just whipped together a quick and (very!!) dirty C program to do it for me. I'm not too proud of it, but it was the best I could do at the time.Code:1,"field1","field2","field3" 2,"field1a","field2a","field3a" etc.
I tried looking up documentation on tr, awk and sed, but alas I don't have nearly enough experience with either one (read: none) to be able to do anything with them.
I'm trying to get better with shell scripting, so I was hoping someone could give me a hand on how to do this with pure bash scripting, (i.e. no Python, Ruby, or any other languages, please.)
Bookmarks