How to replace line-breaks with commas using grep in TextWrangler?

funkylaundry picture funkylaundry · Jul 26, 2011 · Viewed 67.8k times · Source

I have a text-file container a number of lines, which I need to turn into a csv. What is the easiest way to replace all the line-breaks with ", ". I have TextWrangler and read that it would do so by using grep and regular expressions, but have very little experience using regular expressions and don't know how grep works. Anyone who can help me get started?

Answer

Andrew Clark picture Andrew Clark · Jul 26, 2011
  1. Choose Find from the Search menu. TextWrangler opens the Find window.
  2. Select the "Grep" checkbox
  3. Type the string you are looking for ("\n" or "\r\n" or "\r") in the Find textfield.
  4. Type the replace string (", ") in the Replace text field.
  5. Click "Replace All"

See chapters 7 and 8 of the TextWrangler User Manual if you have problems.