Linux 从BASH中的HTTP响应中提取body部分

Linux 从BASH中的HTTP响应中提取body部分,linux,bash,shell,awk,sed,Linux,Bash,Shell,Awk,Sed,有人能帮我弄清楚如何使用bash脚本从下面的响应中的headers部分提取body吗 我试过awk,sed,grep。。。通过在这里查看一些现有的解决方案,但收效甚微。 如果我需要提供任何其他信息,请告诉我 HTTP/1.1 200 OK Cache-Control: max-age=604800 Content-Type: text/html Date: Mon, 24 Jul 2017 10:16:19 GMT Etag: "359670651+gzip+ident" Expires: Mo

有人能帮我弄清楚如何使用bash脚本从下面的响应中的headers部分提取body吗

我试过awk,sed,grep。。。通过在这里查看一些现有的解决方案,但收效甚微。 如果我需要提供任何其他信息,请告诉我

HTTP/1.1 200 OK
Cache-Control: max-age=604800
Content-Type: text/html
Date: Mon, 24 Jul 2017 10:16:19 GMT
Etag: "359670651+gzip+ident"
Expires: Mon, 31 Jul 2017 10:16:19 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (iad/182A)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 50px;
        background-color: #fff;
        border-radius: 1em;
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        body {
            background-color: #fff;
        }
        div {
            width: auto;
            margin: 0 auto;
            border-radius: 0;
            padding: 1em;
        }
    }
    </style>    
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is established to be used for illustrative examples in documents. You may use this
    domain in examples without prior coordination or asking for permission.</p>
    <p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
HTTP/1.1200正常
缓存控制:最大年龄=604800
内容类型:text/html
日期:2017年7月24日星期一格林尼治标准时间10:16:19
Etag:“359670651+gzip+ident”
到期时间:2017年7月31日星期一格林尼治标准时间10:16:19
最后修改:2013年8月9日星期五23:54:35 GMT
服务器:ECS(iad/182A)
改变:接受编码
X缓存:命中
内容长度:1270
示例域
身体{
背景色:#F0F2;
保证金:0;
填充:0;
字体系列:“开放式Sans”、“Helvetica Neue”、Helvetica、Arial、Sans serif;
}
div{
宽度:600px;
保证金:5em自动;
填充:50px;
背景色:#fff;
边界半径:1米;
}
a:链接,a:已访问{
颜色:#38488f;
文字装饰:无;
}
@介质(最大宽度:700px){
身体{
背景色:#fff;
}
div{
宽度:自动;
保证金:0自动;
边界半径:0;
填充:1em;
}
}
示例域
此域用于文档中的说明性示例。你可以用这个
未经事先协调或请求许可,示例中的域

我没有正确解释,我的意思是从http响应中提取主体,而不是html响应的主体。换句话说,通常如何提取http的正文响应(响应中在\r\n\r\n之后的部分),此代码仅用于演示目的…

sed-n'//,//p'文件名
sed -n '/<body>/,/<\/body>/p' filename
打印从到

sed-n'//,//p'文件名的所有内容

打印从到的所有内容以输出
正文
内部HTML(不带
正文
标记):


sed-n'/输出
body
内部HTML(不带
body
标记):


sed-n'/您的预期输出应该是什么样子?可能重复的@JFS31应该在\r\n\r\n ie之后开始。只有身体部分应该是什么样子?可能重复的@JFS31应该在\r\n\r\n ie之后开始。只有身体部分从
sed -n '/<body/,/<\/body>/{//!p}' file