find / replace line breaks in textedit

nameshock

macrumors newbie
Original poster
Mar 14, 2011
4
0
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?

ex:

john.com
mary.com
todd.com

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

>

www.john.com
www.mary.com
www.todd.com

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?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
24,490
13
London
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.

Code:
sed 's/^/www./' <test.txt >test1.txt
 

subsonix

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

Code:
while read line; do echo "www."$line ; done < domain_names.txt > www_added.txt
 

jahala

macrumors regular
Feb 7, 2008
195
8
Pick a more powerful text editor

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?
Macs ship with emacs and vim accessible via the terminal. You can also download versions that act more like a Mac application.

MacVim from http://code.google.com/p/macvim/
emacs choices are listed at http://www.emacswiki.org/emacs/EmacsForMacOS

Other options can be seen at http://mac.appstorm.net/roundups/office-roundups/top-10-mac-text-editors/

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:
:%s/^/www./

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

McGordon

macrumors member
Dec 28, 2010
63
1
Scotland
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.
 

nameshock

macrumors newbie
Original poster
Mar 14, 2011
4
0
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
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
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
It is possible with sed in TextMate: choose Text > Filter Through Command

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

in the text box.

Hit enter.
 
Last edited:

neatnate

macrumors newbie
Jul 25, 2012
4
0
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.
 

NoBoMac

Moderator
Staff member
Jul 1, 2014
2,465
886
Resurrecting a 7yo thread?

From Terminal, can also do:

Code:
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.