Home > OS >  Extract text using awk that is in between to special characters
Extract text using awk that is in between to special characters

Time:05-02

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'/>

CodePudding user response:

Using awk

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

Using sed

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