Linux – How to Append Text to a Specific Line in a File

linuxsedtext processing

If I needed to append a username to the end line 32 on a file, how would I do so?

I can find on Google how to add text to the beginning of a line with sed, but I can't figure out how I would append it to the end, or even the middle, if that was possible.

Best Answer

You can substitute your text for the line end ($) like this:

sed -e '32s/$/your_text/' file

To insert text in the middle of the line some information about the line structure would be useful.

Related Question