• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unix Shell Script for pulling the information based on ID

 
sudha swami
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The below address information is logged in the file x.log. If the user enters 2, iwant the address information starting with <address> ..</address> to be displayed
on the console. Is it better to use shell script. Any help is appreciated.

<ADDRESS>
<ID> 1</ID>
<STREET>ABC </STREET>
</ADDRESS>

<ADDRESS>
<ID> 2</ID>
<STREET>XYZ </STREET>
</ADDRESS>


regards
sudha
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you want to be displayed?
XYZ?

would do the trick.

The 2 is the pattern to search for with grep.
-n1 gives 1 line of context before and behind.

tail -n1 only displays 1 line from the end backwards.
In a shell script xlogsearch.sh, you would write

and call it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic