Solved

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

Posted on 2015-01-28
3
72 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now