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

reh

macrumors 6502a
Original poster
Oct 24, 2003
639
1
I have over 100 files that need text appended to both the beginning and end of the file. Is there a free application or command-line method for accomplishing this?

All of the text that's added to the beginning will be the same and all of the text added to the end will be the same.
 
I found a command line solution. I'll post it in case someone else needs it.
Code:
for x in *.html; do (cat beginning; cat $x; cat end) > tmp; mv tmp $x; done

Replace the "*.html" bit if your text files have a different extension. The lines you want added to the beginning of each file should be stored in a file named "beginning" and the end files in a file named "end". Everything should be in the same folder.

Might want to backup your files first, just in case. ;)
 
grep is much simpler (one command to do all referenced above), plus, it does searching by variables to substitute data between tags for easy updating over time through a cron job.

May want to take a look at the manual, but it will cover anything you could possibly want to do to a text file, and it exists under every OS and architecture. (windows through a 3rd party download)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.