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;/" Home.java

 

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
do
  sed -i "" "1s/^/package home;/" $f 
done

 




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

required
required


Leave a Reply

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