Alex Rivera | Logout

Shell script to append text to each file?

Asked 2011-04-07T19:10:19.410
27

I have a folder full of text files. I need to append the same block of text to each of them (and of course overwrite the original file).

I was wondering what the correct Bash shell syntax would be for this. Would I use cat?

I have done a few batch scripts but I'm not a Bash expert. Any suggestions appreciated.

Edit
Report

1 Answer

36

Use append redirection.

for f in *.txt
do
  cat footer >> "$f"
done
answered 2011-04-07T19:18:58.723

Your Answer