zkwsk
zkwsk

Reputation: 2136

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

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?

Upvotes: 19

Views: 72673

Answers (2)

Andrew Clark
Andrew Clark

Reputation: 208565

  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.

Upvotes: 34

aimee w
aimee w

Reputation: 17

Alternatively, and with only two pieces of software (Excel and Notepad++, which is also free and AWESOME).

  1. Take your list (I assume it's one per line, in a column, for example):
  2. Remove any empty cells
  3. Copy the addresses, and Paste Special>Transpose (this put them into cells going from A-->).
  4. Copy list into notepad++ - you'll note that it shoves them in as one long list, losing that irritating table structure.
  5. Find the shortest clear space (but use the entire space) between two email addresses, and replace all with a ","
  6. Then find all remaining spaces (i go with one space at a time), and replace with nothing (i.e. the 'replace with' box is empty).

Et voila!

and you know you can also save stuff as comma-separated values, right?

Upvotes: 0

Related Questions