Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

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.

>

http://www.john.com
http://www.mary.com
http://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?
 
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
 
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
 
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.
 
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.
 
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
 
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:
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.