Solved

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

Posted on 2015-01-28
3
75 Views
Last Modified: 2015-01-30
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?
0
Comment
Question by:mickt
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40575240
What do you want that line to do?
What is the line you want to edit, and what do you want the result to be?
Did you want something like this?
sed -i 's@#filter = \[ "a/.*/" ]@filter = [ "a/sda/", "a/sdb/", "a/sdc/", "r/.*/" ]@g'  /etc/lvm/lvm.conf
0
 

Author Comment

by:mickt
ID: 40575259
Good stuff.  Adding \ did the trick.

Change from:

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

to:

filter = [ "a/sda/", "a/sdb/", "a/sdc/", "r/.*/" ]
0
 

Author Comment

by:mickt
ID: 40579411
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
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to count occurrences of each item in an array.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question