Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get string between 2 defferent quotes

I trying to get device addres from scanimage -L which return

device `canon_dr:libusb:003:004' is a CANON DR-C125 scanner

Thanks.

I come up with this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

grep -Po '`\K[^']+'

but dont understend how to properly isolate special symbols

>Solution :

You can use

grep -Po "\`\\K[^']+"

Note that inside the double quoted string literal, the backtick and backslash need escaping.

You can also use awk here:

awk -F"[\`']" '{print $2}'

See the online demo:

#!/bin/bash
s='device `canon_dr:libusb:003:004'"'"' is a CANON DR-C125 scanner'
grep -Po "\`\\K[^']+" <<< "$s"
# => canon_dr:libusb:003:004
awk -F"[\`']" '{print $2}' <<< "$s"
# => canon_dr:libusb:003:004
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading