LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How do I replace ' with sed.... (https://www.linuxquestions.org/questions/linux-newbie-8/how-do-i-replace-with-sed-596654/)

@ngelot 11-02-2007 12:25 PM

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

druuna 11-02-2007 01:47 PM

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.

@ngelot 11-02-2007 07:04 PM

I was sure I tried double-quotes...

Anyway - this works:

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

Thanks!


All times are GMT -5. The time now is 06:13 PM.