'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'/>
Solution 1:[1]
Using awk
$ awk -F"'" '{print $2}' file
/PATH/vsrx.qcow2
Using sed
$ sed -n "s/[^']*'\([^']*\).*/\1/p" file
/PATH/vsrx.qcow2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HatLess |
