To extract the text between
and in an XML file, you can use the following command:
bashsed -n '//,/<\/com.eds.travel.fares.ping.response>/p' file.txt | grep -v '\|<\/com.eds.travel.fares.ping.response>'
This command uses sed
to print lines from the XML file that are between the start and end tags of
. Then, it uses grep
to exclude the start and end tags themselves from the output.
You can replace file.txt
with the actual path to your XML file.
Please note that using regular expressions to parse XML can be error-prone for complex cases. It’s recommended to use an XML parsing library if your XML structure is more complex than the example provided.
المزيد من المعلومات
لقد أردت استخراج النص بين علامتي
و من ملف XML. يمكنك استخدام أداة
awk
بدلاً من sed
و grep
لتحقيق ذلك. إليك الأمر الذي يمكنك استخدامه:
bashawk 'BEGIN { RS=""; ORS="" } NR>1 { sub(/<\/com.eds.travel.fares.ping.response>.*/,""); print $0 }' file.txt
هذا الأمر يستخدم awk
لقراءة الملف وفصله بناءً على علامة البداية
، ثم يستخدم sub
لإزالة النص بين علامة النهاية ونهاية السطر، وأخيرًا يطبع النص المستخرج.