Search code examples
regexlinuxsedredhat

Appending to file, sed unterminated address regex


I'm trying to append to the end of a file, using the style from this answer but I get the error:

sed: -e expression #1, char 16: unterminated address regex

the command (I've also tried without the -i and same error):

sed -i -e '\$ahaha_value=26' example.txt

where I'm expecting $ to get the end of the file and a to append.

I've looked at these questions here, here, and here. The issues there seem to be regex based and I don't see the issue with my regex.


Solution

  • With single quotes you don't need to escape $ sign since it's not going to be evaluated by shell.

    Either

     sed -e '$a...'
    

    or

    sed -e "\$a..."