Need row number with Xml tags value

Hi,
Need help.
My source file contain data like:

1       <?xml version="1.0"?> <Status>EGZAAE09</Status><Perform>002</Perform><DATE>2013-05-27</DATE>
1       <?xml version="1.0"?> <Status>ECBAE09</Status><Perform>002</Perform><DATE>2013-05-27</DATE>
2       <?xml version="1.0"?> <Status>Y78ZAAE08</Status><Perform>002</Perform><DATE>2013-05-27</DATE>
3       <?xml version="1.0"?> <Status>TRE8ZA9</Status><Perform>002</Perform><DATE>2013-05-27</DATE>

I need only <Status> value which is i'm getting with below command:

perl -nle 'print /(?<=Status>).*?(?=<\/Status>)/g' File_Name

Output is :
EGZAAE09
ECBAE09
Y78ZAAE08
TRE8ZA9

But i want row number also like:

1	EGZAAE09
1	ECBAE09
2	Y78ZAAE08
3	TRE8ZA9

Pls help me to get this

with awk

awk -F "  +|<Status>|</Status>" '{ print $1, $3}'

This way is often used to remove html/xml tags.

awk '{gsub(/<[^>]*>/, " ");print $1,$2}'

If for some reason, you need perl only syntax, this will do

perl -nle 'print /(.+(?=\<\?xml version="1.0"\?\>))|((?<=\<Status\>).+(?=\<\/Status\>))/g' file_name
1 Like