nickcrv06
nickcrv06

Reputation: 127

Extract text using awk that is in between to special characters

I have the following file:

# cat vsrxa-1.xml

<some text>
      <source file='/PATH/vsrx.qcow2'/>
<some text>

I am trying to print only what is in between the ('') Something like this:

<source file='/PATH/vsrx.qcow2'/>

To print only: 
/path/vsrx.qcow2

But not to print:
'/PATH/vsrx.qcow2'

I tried using cat <file> | awk -F[=,] '{print $2}' but I only get: '/PATH/vsrx.qcow2'/>

Upvotes: 0

Views: 147

Answers (1)

sseLtaH
sseLtaH

Reputation: 11237

Using awk

$ awk -F"'" '{print $2}' file
/PATH/vsrx.qcow2

Using sed

$ sed -n "s/[^']*'\([^']*\).*/\1/p" file
/PATH/vsrx.qcow2

Upvotes: 1

Related Questions