Issue
I would like to prepend some text to multiple files in bash, I've found this post that deals with prepend: title="prepend to a file one liner shell?">prepend to a file one liner shell?
And I can find all the files I need to process using find:
find ./ -name "somename.txt"
But how do I combine the two using a pipe?
Solution
You've got several options. Easiest is probably sed:
find ./ -name somename.txt -exec sed -e '1i\
My new text here' {} \;
It'll be faster if you add '2q' to tell it you're done after prepanding the text, and if will happen in place in the file with the -i flag:
find ./ -name somename.txt -exec sed -i .bak -e '2q;1i\
My new text here' {} \;
To prepend multiple lines, you'll need to end each one with a backslash.
That leaves the original files around with a .bak
extension.
Answered By - Charlie Martin Answer Checked By - Clifford M. (WPSolving Volunteer)