From above line, I need to print Start fro" /> From above line, I need to print Start fro" /> From above line, I need to print Start fro"/>

How to use grep command to print value of a variable in a line?

924 Views Asked by At

For Example,consider the below line

<WORKFLOWLINK CONDITION ="" FROMTASK ="Start" TOTASK ="cmd_START_RUN"/>

From above line, I need to print Start from FROMTASK ="Start" using grep command or using any command.

3

There are 3 best solutions below

2
Gilles Quénot On

Try doing this :

$ xmllint --xpath 'string(//WORKFLOWLINK/@FROMTASK)' file
Start

$ xmlstarlet sel -t -v 'string(//WORKFLOWLINK/@FROMTASK)' file
Start

$ saxon-lint --xpath 'string(//WORKFLOWLINK/@FROMTASK)' file
Start
0
D3Hunter On

If you just want value of FROMTASK, or some fixed variables try sed:

sed -nre 's/^.*FROMTASK *= *"([^"]*)".*$/\1/p' file

If you want to get value of any variables, try xmllint as sputnick answered

Use sudo apt-get install libxml2-utils(for debian) or yum install libxml2-utils to install it.

0
ppm9 On

Since your tags don't suggest this is about XML, simply use cut command

cut -d "\"" -f4