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

70,095
  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.

Share:
70,095
zkwsk
Author by

zkwsk

Updated on July 05, 2022

Comments

  • zkwsk
    zkwsk almost 2 years

    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?

  • zkwsk
    zkwsk almost 13 years
    I was actually trying to do exactly that but now I realize that I should be using carriage return \r rather than unix line breaks \n. Thanks for the help
  • Sam YC
    Sam YC over 11 years
    is Notepad++ really available in Mac?
  • SexyBeast
    SexyBeast almost 10 years
    Precisely. In OSX Mavericks at least, \n was returning a blank replace result, had to change it to \r..
  • PatrickT
    PatrickT over 9 years
    Notepad++ is not available for Mac at time of writing and textwrangler is arguably the closest substitute, though it doesn't seem to have as many features. At any rate, if you're going to grep, probably not that useful to be inside the editors, command-line is more powerful, you can grep inside several documents/directories at once, etc..
  • user535673
    user535673 almost 8 years
    The TextWrangler method should also work in Notepad++ or any other text editor that does regular expressions – no need for Excel. Generally, though, I find TextWrangler’s regular expressions more reliable than Notepad++’s.
  • lib
    lib over 7 years
    actually is possible to do it in notepad++ alone , without excel (provided you are on Windows)