Need Help On REG EXP in unix

Respected All,

I have a very big xml in that i want to search only below 3 lines.

<target name ="UpgradePrimaryBox" depends ="configureBox1">
<echo> Finished Upgrading Primary Box </echo>
</target>

grep -i "<target.*UpgradePrimaryBox" this gives me the first line.
then i need to match second line and the </target>.

Please help me.

Thanks,
Amey

Hi ameyrk,

There is an option that print following lines of a match. I don't know if your version support it. Try it:

$ grep -A2 -i "<target.*UpgradePrimaryBox"

Regards,
Birei

Birei,

correct my version does not support.

my question is like grep -i "<target.*UpgradePrimaryBox<followed by new line><then followed by target>"

any help?

grep matches lines. If what you want isn't a matching line, it doesn't really do it. It's not a programming language, you can't tell it "if x, print two more lines."

awk is a programming language however. You can tell it "if x, print 2 more lines".

awk '/<target.*UpgradePrimaryBox/ { print; getline; print; getline ; print }' file

Wow that really worked. In this case we know there are 3 lines but if the opening and closing target are really big then any idea on that?

thanks Corona

If it's too big for awk on your sytem try nawk.

Solution to post #5:

sed -n '/<target.*UpgradePrimaryBox/,/<\/target>/p' inputfile
 
$ nawk '/\<target/ , /\<\/target>/' input.txt
<target name ="UpgradePrimaryBox" depends ="configureBox1">
<echo> Finished Upgrading Primary Box </echo>
</target>