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

Jesse Smith

macrumors member
Original poster
Is there any way to use Terminal to add text to the end of all Files in a directory? TexFinder X is close, but it only searches and replaces existing text. If there's not the same text at the end of every file, it can't do it.
 
Sure, this should do it:

Code:
cd ~/path/to/files
for f in *; do echo 'text to be appended' >> "$f"; done

If you'd rather not type the path (in the cd part), you can type "cd " and then drag the folder onto the Terminal.

Also, if you have a lot of text to be appending, you could try this:
  1. Create append.txt file with your content. Save this somewhere outside your directory of files.
  2. Change the "do echo" bit to
    Code:
    do cat ~/path/to/append.txt >> "$f"; done
 
Thanks. That worked. I had been trying to do this...

Code:
for f in ~/html/*.html; do echo "Processing $f file.." && cat ~/close.html >> $f; done

Put your closing tags in a file... well call it close.html and we'll jsut put it in your home directory /Users/youruser/close.html. Well assume your docs are in /Users/youruser/html

Open Terminal.app and do the following command:

find ~/html -type f -name "*.html" -exec cat ~/close.html >> {} \;

but it just kept saying the directory didn't exist.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.