app to mass-append text?

Discussion in 'Mac Apps and Mac App Store' started by reh, Aug 16, 2006.

  1. reh macrumors 6502a

    Joined:
    Oct 24, 2003
    Location:
    Arkansas
    #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.
     
  2. reh thread starter macrumors 6502a

    Joined:
    Oct 24, 2003
    Location:
    Arkansas
    #2
    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. ;)
     
  3. projectle macrumors 6502

    Joined:
    Oct 11, 2005
    #3
    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)
     

Share This Page