Multiple Substring Outputs

Hello,

I am reading a file with millions of lines in it. Each line is big line containing several xml tags. I need to Output just the value of two tags in a seperate flat file.

For eg- I need to output whats present in <ComponentName> something </ComponentName> and another tag is <ElapsedTime>362</ElapsedTime>.

Currently i am handling this in 3 steps-

  1. Reading full file for capturing all component names- Using Awk
  2. Then again reading full file for all Elapsed Times - Using Awk
  3. And then Finally using paste command to merge output of above

I intend do all above in 1 step only.

That is capturing both component name and elapsed time simulatneously and writing them into different columns in a file.

So this will save some time.

Can somebody pls guide on how to take multiple subsets out of a string at one go.

Any help would be much appreciated.

Thanks,
Sunny.

Maybe something like that? I'm not sure if it will work with a file. Test it.

echo "<ComponentName> something </ComponentName> asdfdf werwer <ElapsedTime>362</ElapsedTime>" | grep -o -E '((<ComponentName>)(.*)(</ComponentName>))|((<ElapsedTime>)(.*)(</ElapsedTime>))' | tr  "<|>|/" "\t" | awk '{print $2}' | fmt -s

Somehow, my shell is not recognizing "-o" option with grep.