How to Append / Insert Multiple New Line in a File Using Shell Script?
Insert Multiple New Line in a File Using Shell Script?
Do you want to insert multiple lines below of a specific line sed command will help us with different cases,
For example few lines saved in a file name of linuxfaq.txt that contain
but i would like to add three lines one by one "red, green, blue" next line of colors
Note : -i specified that save the changes in file
sed -i "/colors/ared\ngreen\nblue" linuxfaq.txt
Once you have executed that command output will be
If are you Passing String by Variable,
sed -i "/colors/ared\ngreen\n$color" linuxfaq.txt
How you can insert lines from a file.
sed '/colors/r toadd.txt' linuxfaq.txt
Do you want to append a string at the end of specific line?
Need to add a "linux" word at end of "ext4"
sed 's/ext4/& linux/' linuxfaq.txt