Stream Editor (sed)

To insert/append to file (Linux)

sed '3i hello world' hello.txt
sed '3a hello world' hello.txt

Apply the change to the file (Linux)

sed -i '3i hello world' hello.txt
sed -i '3a hello world' hello.txt

To insert/append to file (MacOS)

sed -e '3i\
hello world' hello.txt

sed -e '3a\
hello world' hello.txt

Apply the change to the file (MacOS)

sed -I -e '3i\
hello world' hello.txt

sed -I -e '3a\
hello world' hello.txt

Comments

Leave a Reply

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