find / replace line breaks in textedit

Discussion in 'Mac Programming' started by nameshock, Mar 14, 2011.

  1. nameshock macrumors newbie

    Mar 14, 2011
    Is there a way to search for line endings, ¶, in ANY mac text editor so I can say, for instance append a www. or @ symbol infront of 200 lines of domain names?


    find / replace .com<line-ending-symbol>www.


    I can do it on a windows machine with text edit lite, but was wondering if there was a way to do it on a mac?
  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    You want to end up with one huge line? Or you simply want to pre-pend www. to every line. Because if you replace the line end character then there won't be any line breaks afterwards. Anyways you can do it using sed or awk on the command line.

    Edit: assuming your file is called test.txt and you want to output to test1.txt then this will pre-pend www. to very line without wiping out the new lines which is what your example asks for (not replacing as your text says). Note you will have to cd to the directory containing test.txt or use a relative or absolute path.

    sed 's/^/www./' <test.txt >test1.txt
  3. subsonix macrumors 68040

    Feb 2, 2008
    Assuming this is ascii text, you can do it in the terminal like this (although independent of line breaks in this case).

    while read line; do echo "www."$line ; done < domain_names.txt > www_added.txt
  4. jahala macrumors regular


    Feb 7, 2008
    Pick a more powerful text editor

    Macs ship with emacs and vim accessible via the terminal. You can also download versions that act more like a Mac application.

    MacVim from
    emacs choices are listed at

    Other options can be seen at

    In vim or emacs you can use the regular expression given in a previous post. I use vim, so I would type in the following in normal mode:

    I think your best bet would be start using a text editor with a few more features than TextEdit.
  5. McGordon macrumors member

    Dec 28, 2010
    I'm sure the above methods will work, but he asked how to do it in TextEdit. You can paste a line ending into the Find: box, then paste it in the Replace With: box too, followed by your www.

    To capture a line ending, put the cursor at the end of a line, press shift-right arrow to select it, then copy.
  6. nameshock thread starter macrumors newbie

    Mar 14, 2011
    Thanks, yeah I am actually using TextMate and since it was so expensive I figured it could do this.

    I tried shift-right arrow to select, but for some reason (not sure if it is the encoding) it doesn't work. It just thinks that it is some long tab or something.

    And, yes, I am just trying to pre-pend www. to every line
  7. subsonix, Mar 14, 2011
    Last edited: Mar 14, 2011

    subsonix macrumors 68040

    Feb 2, 2008
    It is possible with sed in TextMate: choose Text > Filter Through Command

    and insert: sed 's/^/www./'

    in the text box.

    Hit enter.
  8. nameshock thread starter macrumors newbie

    Mar 14, 2011
  9. neatnate macrumors newbie

    Jul 25, 2012
    In TextEdit, open the find feature. Then, click on the "Replace" checkbox. Place your cursor in the replace text field and type ctrl+shift+return. This should insert a carriage return character that you can use for replacement.
  10. NoBoMac macrumors 68000

    Jul 1, 2014
    Resurrecting a 7yo thread?

    From Terminal, can also do:

    cat filename.txt | sed "s/^/www./" > newfile.txt
    But, easier, imo, via vi/vim/emacs as you don't have to do any file moving/renaming.
  11. Senor Cuete macrumors regular

    Nov 9, 2011

Share This Page