本文介紹了使用 SED 在 XML 標簽之間提取值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我從服務器接收以下格式的數據:
I am receiving data from a server in the following format:
gin</type><sessionId>1601</sessionId><directory><default>DepthOfBook</default><study type="DepthOfBook"/
如何從該字符串中提取值 1601?我一直在嘗試以下方法,但我迷失了正確的 SED 語法:
How can I extract the value 1601 from this string? I have been trying the following, but am lost with the proper SED syntax:
sed -n "/sessionId/,//sessionId/p"
sed -e "s/<sessionId/
/g"| sed -n "/sessionId/,//sessionId/p"
sed -e "s/</
/g"| sed -n "/sessionId/,/sessionId/p"
我如何提取這個值(當字符串是一個長多行字符串時,通常是兩個 XML 標記之間的值)?
How can I extract this value (and generally a value between two XML tags when the string is one, long multiline string)?
謝謝.
推薦答案
這可能對你有用(GNU sed):
This might work for you (GNU sed):
sed '/<sessionId>/!d;s//
/;s/[^
]*
//;:a;$!{/</sessionId>/!N;//!ba};y/
/ /;s/</sessionId>/
/;P;D' file
這篇關于使用 SED 在 XML 標簽之間提取值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!