I have a program that accepts HTTP post of files and write all the POST result into a file, I want to write a script to delete the HTTP headers, only leave the binary file data, how to do it?

The file content is below (the data between `Content-Type: application/octet-stream` and `------------KM7cH2GI3cH2Ef1Ij5gL6GI3Ij5GI3` is what I want:

```
POST /?user_name=vvvvvvvv&size=837&file_name=logo.gif& HTTP/1.1^M
Accept: text/*^M
Content-Type: multipart/form-data; boundary=----------KM7cH2GI3cH2Ef1Ij5gL6GI3Ij5GI3^M
User-Agent: Shockwave Flash^M
Host: 192.168.0.198:9998^M
Content-Length: 1251^M
Connection: Keep-Alive^M
Cache-Control: no-cache^M
Cookie: cb_fullname=ddddddd; cb_user_name=cdc^M
^M
------------KM7cH2GI3cH2Ef1Ij5gL6GI3Ij5GI3^M
Content-Disposition: form-data; name="Filename"^M
^M
logo.gif^M
------------KM7cH2GI3cH2Ef1Ij5gL6GI3Ij5GI3^M
Content-Disposition: form-data; name="Filedata"; filename="logo.gif"^M
Content-Type: application/octet-stream^M
^M
GIF89an^@I^^M
------------KM7cH2GI3cH2Ef1Ij5gL6GI3Ij5GI3^M
Content-Disposition: form-data; name="Upload"^M
^M
Submit Query^M
------------KM7cH2GI3cH2Ef1Ij5gL6GI3Ij5GI3-

```
['https://Stackoverflow.com/questions/4236020', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/197036/']
You want to do this as the file is going over, or is this something you want to do after the file comes over?

Almost any scripting language should work. My AWK is a bit rusty, but...

```
awk '/^Content-Type: application\/octet-stream/,/^--------/'

```

That should print everything between `application/octet-stream` and the `----------` lines. It might also include both those lines too which means you'll have to do something a bit more complex:

```
BEGIN {state = 0}
{
    if ($0 ~ /^------------/) {
        state = 0;
    }
    if (state == 1) {
        print $0
    }
    if ($0 ~ /^Content-Type: application\/octet-stream/) {
        state = 1;
    }
}

```

The `application\/octet-stream` line is after the print statement because you want to set `state` to `1` after you see `application/octet-stream`.

Of course, being Unix, you could pipe the output of your program through awk and then save the file.
If you use Python, [`email.parser.Parser`](http://docs.python.org/library/email.parser.html#parser-class-api) will allow you to parse a multipart MIME document.