Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2015-01-28
3
Medium Priority
?
83 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 85

Accepted Solution

by:
ozo earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will focus on how to use WhizBase as a tool for sending ICQ messages to ICQ. Here I will use a new technology in WhizBase, published in WhizBase 5.1 version. In this tutorial I will use 3 files, pager.wbsp for the processing, e…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 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