Linux prepend content to a file

Prepend content to a file

Use sed with -i option. You can also specify the line to which the content will prepend to.

sed -i '' '1s/^/package home;/"


Prepend content to multiple files

Here I need to add a package to 200 java files. To do this manual would be tedios. 

for f in *.java
  sed -i "" "1s/^/package home;/" $f 


Subscribe To Our Newsletter
You will receive our latest post and tutorial.
Thank you for subscribing!


Leave a Reply

Your email address will not be published. Required fields are marked *