Mailinglist Archive: opensuse (1445 mails)

< Previous Next >
[opensuse] bash - howto sudo echo X >> Y (sed?)

I have an interesting question. I have a file that I need to append
information to that is owned by root. Initially I wanted to use echo:

sudo echo "X" >> y.txt

But, of course the echo has root privileges, but the redirection does not. So
then I though about sed. It works, but how do I tell sed to 'append to end of

The last word in the existing file is custompkgs, but that isn't guaranteed to
stay that way. As it sits, I can:

sudo sed -i '/\/custompkgs/s#$#\n\n[local]\nServer = file:///repo\n#'

How can I omit searching for a word and just tell sed to append at end of

Or, how can I use echo or cat to do the same thing, but overcome the lack of
privilege on the >> ?

David C. Rankin, J.D.,P.E.
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse+owner@xxxxxxxxxxxx

< Previous Next >