Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: append text to last line of file

How can I add a percentage symbol % to the end of the last line in a text file?

I do not want the % to be on a new line, it must be at the end of the last line.

Thanks!

like image 381
Rich Avatar asked Sep 07 '10 10:09

Rich


People also ask

How do I add text to the end of a file in Linux?

Using tee Command: The tee command copies the text from standard input and writes it to the standard output file. The tee provides -a option to append the text to the file.

How do I add a line to the end of a file in Linux?

There are two standard ways of appending lines to the end of a file: the “>>” redirection operator and the tee command. Both are used interchangeably, but tee's syntax is more verbose and allows for extended operations.

Which command is used to append some text at the end of some file?

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.


1 Answers

sed '${s/$/%/}' file
like image 151
ghostdog74 Avatar answered Nov 16 '22 02:11

ghostdog74