Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need linux command.

 
praneeth ram
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
test.xml.gz

<MyName Owner="Praneeth" Status="ALIVE">
<Empid>033516</Empid>
<DOB>2020</DOB>

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.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With -E you get extended grep, extended by regular expressions. "(a|b|c)" means "find a or b or c":

Another approach, if DOB always follows Empid, and 2020 is allways following 033516 is, to print one additional line of output:



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



Maybe there is something more simple out there, than xmlstarlet.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic