I am receiving data from a server in the following format:
gin1601 DepthOfBook<
Something like this would work:
sed -e 's/<\/sessionId>/<\/sessionId>\n/g' | sed -n 's/.*<sessionId>\([^<]*\)<\/sessionId>.*/\1/p'
First part is because sed tries to eat up as much of a single line as possible when matching, this will find all sessionId
occurences and split them up on a line on its own.
Next part matches stuff between the sessionId
tags.
This might work for you (GNU sed):
sed '/<sessionId>/!d;s//\n/;s/[^\n]*\n//;:a;$!{/<\/sessionId>/!N;//!ba};y/\n/ /;s/<\/sessionId>/\n/;P;D' file
I would suggest using XPath, which is an XML query language. If you have the Perl XML::XPath module installed then you could simply use the following command in your shell:
xpath -q -e '//sessionId/text()' <input_file>