LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-02-2007, 12:25 PM   #1
@ngelot
Member
 
Registered: Oct 2004
Posts: 84

Rep: Reputation: 15
SOLVED: How do I replace ' with sed....


I'm making a autoscan-script with scanimage and want to set up an "autofind-device", but I don't know how to replace ` or '

This is the scanimage command for listing supported devices:

scanimage -L

and the output is:
Code:
device `hpaio:/usb/HP_LaserJet_3052?serial=00CNSKN09261' is a Hewlett-Packard HP_LaserJet_3052 all-in-one
I would like to to something like:

scanimage -L | sed 's/device \`/\n/' | sed s/\'/\n/' | awk 'NR==2'

or

scanimage -L | awk '/\`/,/\'/'

So that the output is:

hpaio:/usb/HP_LaserJet_3052?serial=00CNSKN09261

But I can't get sed (or awk) to remove/read the ` or the '

How can I do this?

@ngelot

Last edited by @ngelot; 11-02-2007 at 07:05 PM.
 
Old 11-02-2007, 01:47 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The ` does not need escaping:

$ cat input | sed 's/device `/\n/'

hpaio:/usb/HP_LaserJet_3052?serial=00CNSKN09261' is a Hewlett-Packard HP_LaserJet_3052 all-in-one


Try using double qoutes for the second sed command:

$ cat input | sed 's/device `/\n/' | sed "s/'/\n/"

hpaio:/usb/HP_LaserJet_3052?serial=00CNSKN09261
is a Hewlett-Packard HP_LaserJet_3052 all-in-one


Hope this helps.
 
Old 11-02-2007, 07:04 PM   #3
@ngelot
Member
 
Registered: Oct 2004
Posts: 84

Original Poster
Rep: Reputation: 15
I was sure I tried double-quotes...

Anyway - this works:

cat input | sed 's/device `//' | sed "s/'/\n/" | sed q

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed replace string octeto Programming 4 06-06-2007 02:09 AM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
Replace substring with SED marri Programming 2 07-09-2005 05:18 PM
[sed] replace string? chuanyung Programming 3 03-11-2004 08:42 PM
Sed - suitable to replace CR LF? J_Szucs Programming 3 05-12-2003 06:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration