CSV File

VeeDubbs

Limp Gawd
Joined
Dec 9, 2005
Messages
398
Hi All -

I have a list of users that I need to get in the following format:

Code:
"username","first name","last name","email@email.com","student id","password"

RIght now I have that format minus the needed quotation marks (""). So in notepad I just searched for a , and replaced it with "," -- that got me to here:

Code:
username","first name","last name","email@email.com","student id","password

I now need to get quotes at the very beginning and the very end of each line -- I have around 6,000 lines and do not want to do it by hand. Any quick ways to accomplish this?
 
You could do it easily from a command prompt:

for /f "delims=" %1 in (oldfilename.csv) do echo "%1" >> newfilename.csv

The only problem could be if you have space(s) at the end of the line, the space(s) would be included before the last quote. You could do a find and replace to fix that.
 
Thanks!

I'll give that a try. I'm also giving it a go with sed -- I always forget about sed!
 
Sed and Perl regexes are pretty similar IIRC.

You can try something like this:
Code:
cat inputFile | perl -pe 's/([^,\n]+)/"$1"/g'
or you can run it directly on the file like:
Code:
perl -pe 's/([^,\n]+)/"$1"/g' -i inputFile
 
for csv, you don't need to quote each column unless it contains quote or comma characters (not sure if there are other special chars) (assuming you have a good csv parser), but i guess i'm a little late for that :/
 
Shove it to an access database and then take it out with quotes around the columns
 
Back
Top