above code is working for only first element, if I want to fetch the second element using " head -2 " it returns two elements from top to bottom in a single call, can you please help me with the solution.
grep "^<dir" file | tail -n+2 | head -1
<dir>doc/store834/extract</dir>
This works as the desired data is in one single line only, and it is not an "XML problem". For requests dealing with e.g. several layered structures extending across more than one line, there are better suited tools out there to handle xml structures.