Append new lines to a file or variable in BASH

Home > Search
  by

The sed command with the a (append) flag can be used to append lines to a file or variable. For example, let's say you have a file or variable with the following text.

Hello World

 

The following command will add "New Text" to the file or variable. The a flag in this command is used to append.

sed -i '/Hello World/a New Text' $foo

 

In this example, the file or variable will have the following output.

Hello World
New Text

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments