Link to home
Start Free TrialLog in
Avatar of mickt
micktFlag for Ireland

asked on

What is sed command to edit line that includes quotes and spaces?

I'm trying to edit a line in a file as follows

sed -i 's@#filter = [ "a/.*/" ]@filter = [ "a/sda/", "a/sdb/", "a/sdc/", "r/.*/" ]@g' /etc/lvm/lvm.conf

It does not work.  I've tried enclosing in quotes etc. but without success.

Can anyone advise as to the correct command?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mickt

ASKER

Good stuff.  Adding \ did the trick.

Change from:

#filter = [ "a/.*/" ]

to:

filter = [ "a/sda/", "a/sdb/", "a/sdc/", "r/.*/" ]
Avatar of mickt

ASKER

If I try to include above in ssh I receive an error:

# ssh $i sed -i 's@#filter = \[ "a/.*/" ]@filter = [ "a/sda/", "a/sdb/", "a/sdc/", "r/.*/" ]@g'  /etc/lvm/lvm.conf
sed: -e expression #1, char 8: unterminated `s' command


I can resolve as follows but I'd prefer to not use EOF if possible.
ssh $i <<EOF
ssh $i sed -i 's@filter = \[ "a/.*/" ]@filter = [ "a/sda/", "a/sdb/", "r/.*/" ]@g' /etc/lvm/lvm.conf
exit
EOF