但它似乎不起作用(它似乎返回了整个输出,而不是提取.谁能告诉我怎么做?谢谢!吉姆 解决方案 这可能对你有用(GNU sed):sed '/\n/!{s//\n&/;s//&\n/};/^/P;D'文件如果某行尚未修改,则在 </message> 之前和 </start> 之后插入换行符,并仅打印该行的该部分.I am running a curl command (plus a grep) and I want to extract everything between two patterns from the output.Here's an example output from the curl (and grep): Dload Upload Total Spent Left Speed100 15848 0 15848 0 0 708k 0 --:--:-- --:--:-- --:--:-- 736k</message><refDesc>PULL Task 8c4d1a50-3e05-4b58-8d1a-503e057b586d 4_Place_All_Users_In_Inactive</refDesc><refKey>8c4d1a50-3e05-4b58-8d1a-503e057b586d</refKey><status>SUCCESS</status></syncope21:exec><syncope21:exec xmlns:syncope21="http://syncope.apache.org/2.1"><end>2020-01-22T01:13:44.512Z</end><start>2020-01-22T01:13:44.506Z</start><jobType>TASK</jobType><key>40e64a39-47e7-4428-a64a-3947e7c4286b</key><message>Users [created/failures]: 0/0 [updated/failures]: 0/0 [deleted/failures]: 0/0 [no operation/ignored]: 0/0and I want to extract everything between the </message> and the </start>, e.g., from the above, I want:</message><refDesc>PULL Task 8c4d1a50-3e05-4b58-8d1a-503e057b586d 4_Place_All_Users_In_Inactive</refDesc><refKey>8c4d1a50-3e05-4b58-8d1a-503e057b586d</refKey><status>SUCCESS</status></syncope21:exec><syncope21:exec xmlns:syncope21="http://syncope.apache.org/2.1"><end>2020-01-22T01:13:44.512Z</end><start>2020-01-22T01:13:44.506Z</start>I have tried following:curl -X GET ...." | grep xxxxxxx | sed -n -e '/<\/message>/,/<\/start>/p'but it doesn't seem to be working (it seems to be returning the entire output, rather than extracting.Can someone tell me how to do that?Thanks!Jim 解决方案 This might work for you (GNU sed):sed '/\n/!{s/<\/message>/\n&/;s/<\/start>/&\n/};/^<\/message>/P;D' fileIf a line has not already been amended, insert a newline before </message> and after </start> and print only that part of the line. 这篇关于如何提取两个模式之间的所有内容(使用 sed?)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 13:05