a2p
a2p

Reputation: 11

Sed replacement

I would like to add a sed command in a bash script which replace

#archive_command = ''

to

archive_command = 'rsync -a %p barman@$BACKUP_SERVER_IP:$INCOMING_WALS_DIRECTORY/%f'

I am not an expert and I am always getting errors. I guess is something about single and double quotes

sudo sed -i "s!#archive_command = ''!archive_command = 'rsync -a %p barman@$BACKUP_SERVER_IP:$INCOMING_WALS_DIRECTORY/%f'!" "/my/archive"

Any help is appreciated.

Upvotes: 0

Views: 182

Answers (2)

Ports
Ports

Reputation: 429

...or to make it more readable:):

sed "s/\(#\)\(.[^']*\)\('\)\('\)/\2\3rsync -a %p barman@\$BACKUP_SERVER_IP:\$INCOMING_WALS_DIRECTORY\/%f\4/" file

Upvotes: 0

konsolebox
konsolebox

Reputation: 75458

Try:

sudo sed -i "/^#archive_command = /s|.*|archive_command = 'rsync -a %p barman@\$BACKUP_SERVER_IP:\$INCOMING_WALS_DIRECTORY/%f'|" file

Don't quote if you want those variables to expand:

sudo sed -i "/^#archive_command = /s|.*|archive_command = 'rsync -a %p barman@$BACKUP_SERVER_IP:$INCOMING_WALS_DIRECTORY/%f'|" file

Upvotes: 1

Related Questions