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.
Append Text Using >> Operator The >> operator redirects output to a file, if the file doesn't exist, it is created but if it exists, the output will be appended at the end of the file. For example, you can use the echo command to append the text to the end of the file as shown.
To make a new file in Bash, you normally use > for redirection, but to append to an existing file, you would use >> . Take a look at the examples below to see how it works. To append some text to the end of a file, you can use echo and redirect the output to be appended to a file.
You need to use the >> to append text to end of file. It is also useful to redirect and append/add line to end of file on Linux or Unix-like system.
Use append redirection.
for f in *.txt do cat footer >> "$f" done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With