Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a string to the beginning of each file in a folder in bash?

I want to be able to prepend a string to the beginning of each text file in a folder. How can I do this using bash on Linux?

like image 233
therin Avatar asked Apr 26 '11 21:04

therin


1 Answers

This will do that. You could make it more efficient if you are doing the same text to each file...

for f in *; do 
  echo "whatever" > tmpfile
  cat $f >> tmpfile
  mv tmpfile $f
done
like image 81
drysdam Avatar answered Oct 19 '22 19:10

drysdam