shellsedfreebsdcsh

sed add line at the end of file


I trying to add a line at the end of file (/root/test.conf) with sed. I use FreeBSD and when I try to add a simple line, I always get several errors like:

The file is like this:

#Test
firstLine
secondLine

!p.p
*.*

And I want to add something like this:

(return \n)
!word
other (5 tab between "other" and "/usr/local") /usr/local

If it's not possible with sed, there are another options?

Thank you!


Solution

  • It doesn't sound like you need to use sed at all, maybe just cat with a heredoc:

    cat >>test.conf <<EOF
    whatever you want here
    
    more stuff
    EOF
    

    >> opens test.conf in "append" mode, so lines are added to the bottom of the file, and the <<EOF is a heredoc that allows you to pass lines to cat via standard input.

    To add literal tabs in the interactive terminal, you can use Ctrl-v followed by Tab.