please advice what is wrong with my sed syntax ?

ssh postgres@ sed -i '/archive_command/ s/#BARMAN#[ ]*//g'  /var/lib/pgsql/data/postgresql.conf"

sed: -e expression #1, char 17: missing command

my target is to remove the #BARMAN# string on remote machine

when I do this on local machine its works as the following:

sed -i '/archive_command/ s/#BARMAN#[ ]*//g'  /var/lib/pgsql/data/postgresql.conf"

The syntax is wrong.

It has to be :

ssh postgres@host 'sed -i "/archive_command/ s/#BARMAN#[ ]*//g"  /var/lib/pgsql/data/postgresql.conf"'

You forgot the quotes before and after the command. And added double quotes instead of single quotes so that there is no need to escape it.

  • Careful - there are single-quotes as part of the sed command, which will leave them exposed to splitting.
    – Jeff Schaller
    Sep 13 '17 at 15:36
  • Updated my answer to escape the quotes. @JeffSchaller Edit if I made a mistake. I am not sure if the escaping is done right. Sep 13 '17 at 15:39
  • Since there are no double-quotes or variables in the listed command, wrapping it with double quotes would work for this particular Q.
    – Jeff Schaller
    Sep 13 '17 at 15:40
  • Updated with double quotes. @yael I might not know sed too well, So I ask, is this the right syntax? /var/lib/pgsql/data/postgresql.conf" With only a single double quote at the end of .conf ? Sep 13 '17 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.