Jump to content

convert CSV into another format


Recommended Posts

Yup, that's one seriously strange guy... Still, I guess you'd have to be to call yourself 'why the lucky stiff'. Oh well, to each their own, diff'rent strokes for diff'rent folks, it takes all kinds to make a world and all that.

 

BTW (kinda OT) I've got a whole stack of CSV's that I'm looking to convert into another format. Should I use python or ruby or something like that, or is there a better alternative?

Link to comment
Share on other sites

Ta for splitting that off, Yves. I know, I know, I should've done it myself *flinches in preparation for beating*

 

To give a bit more detail, I've got a bunch of CSVs from MS (yes, I have sold my soul to the devil), which are basically the text strings from most of their programs, with the English and Japanese versions in separate fields. What I want to do is convert those CSVs into something like

 

 [I]Japanese text[/I] /English text/ (file that it came from)

 

-- the formatting's to do with a dictionary program I use. There are a number of other fields in the CSV, but i was just going to throw them out.

 

So, given that info, is python still a good option?

 

TIA (and apologies for the OT post...)

 

Alex

 

PS (more OT) MS puts out these files so that they can 'ensure consistency in translation' for third-party programs, but I've found countless situations where, for no apparent reason, their own files are inconsistent! Not that this suprises me - MS making dodgy software? :o

Link to comment
Share on other sites

If the input file is of the form

english,japanese,other,ignored,fields

then you could convert all the commas to spaces with something like this:

sed "s/,/ /g" inputfile.csv

To convert to the kind of format you want, you could do something like this:

sed "s/^\([^,]*\),\([^,]*\),.*$/\[i]\2\[\/i\] \/\1\//" inputfile.csv

where in this case the first two fields are swapped with a [ i ] and [ /i ] around the japanese and / and / around the english. I'm not quite sure how to get the filename but that should get you started.

Link to comment
Share on other sites

Thanks for that, neddie. I've been reading a little bit about gawk, and I might see if that can do it too. I have a feeling that the filename (or something liek that) might be one of the fields, so I could get around it that way.

 

Thanks for your help!

 

Alex

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...