Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append text to file using sed

Tags:

How can I write text to a file using sed? More specifically I would it add null variables to my blank text file that was created using touch. The syntax of sed is very confusing to me.

like image 834
Geofferey Avatar asked Mar 09 '14 23:03

Geofferey


People also ask

How do I append in sed?

We've learned that sed's “a” and “i” commands can insert or append a new line. The backslash character after the “a” or “i” command doesn't function as the part of an escape sequence, such as \t as a tab or \n as a newline. Instead, it indicates the beginning of the text in the new line we're inserting.

How do you add text to a file in Unix?

You can use the cat command to append data or text to a file. The cat command can also append binary data. The main purpose of the cat command is to display data on screen (stdout) or concatenate files under Linux or Unix like operating systems.

How do I add text to a text file in Linux?

Type the cat command followed by the double output redirection symbol ( >> ) and the name of the file you want to add text to. A cursor will appear on the next line below the prompt. Start typing the text you want to add to the file.


1 Answers

Use $ a.

sed -i "$ a some text" somefile.txt 
like image 194
user4896506 Avatar answered Oct 09 '22 13:10

user4896506