tags:

views:

21

answers:

2

I frequently come across this problem. I have a file:

something
something2
something3

which I want output as:

"something","something2","something3"

any quick tool for this, preferably online?

+2  A: 

If its just a one off thing, it'd be pretty easy to just do it with a search & replace in any advanced-ish text editor...

For example in notepad++:

  • Do a Replace (CTRL+H)
  • Set "Search Mode" to "Extended"
  • Find: \r\n
  • Replace with: ","

(of course you'll need an extra quote at the very start & very end of the file).

If you need to do it more than once, writing a small script/program that did a regular expression replace over the file would be fairly straight forward too.

Edit: If you really wanted to do it online, you could use an online regular expression tester (in this case you want to use \n as the regex and "," as your replace pattern, leaving the other settings alone).

Alconja
+1  A: 

A quick Python hack?

lines = open('input.txt').xreadlines()
txt = ','.join(['"%s"' % x for x in lines])
open('output.txt', 'w').write(txt)
intgr