A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
Linux / UNIX
need linux command.
Joined: Sep 21, 2009
Oct 14, 2010 04:15:15
<MyName Owner="Praneeth" Status="ALIVE">
command for one tag:----- zgrep '<EMPID>033516</EMPID>' test.xml.gz
i am getting expected result.
Now i want to search two tags <Empid>033516</Empid><DOB>2020</DOB> with the above command i am not getting expected result.
i know test.xml.gz contains both tags. but i am not getting this xml file.
can anyone please tell me the command to find the two tags.
Joined: Jun 02, 2003
Dec 30, 2010 23:12:10
With -E you get extended grep, extended by regular expressions. "(a|b|c)" means "find a or b or c":
zgrep -E "(mcedit|oss-compat)" /var/log/popularity-contest.4.gz 1291729846 1256875187 mc /usr/bin/mcedit 1291729841 1256875451 oss-compat /lib/oss-compat/linux
Another approach, if DOB always follows Empid, and 2020 is allways following 033516 is, to print one additional line of output:
zgrep -A1 mcedit /var/log/popularity-contest.4.gz 1291729846 1256875187 mc /usr/bin/mcedit 1291729841 1256875451 oss-compat /lib/oss-compat/linux
A third solution would go for the xml-structure. There are tools to search in xml like xmlstarlet, but I don't know how to use them
zcat /var/log/popularity-contest.4.gz | xmlstarlet sel -t -c "count(/MyName/Empid)" -i "033516" -n -
Maybe there is something more simple out there, than xmlstarlet.
It is sorta covered in the
JavaRanch Style Guide
subject: need linux command.
Array of HashMaps
Oracle date storage?
How to get environment variable ?
Display table row value in another form
Regarding apply JOIN by using JPQL.
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015