How to split file on first empty line in a portable way in shell (e.g. using sed)?

前端 未结 4 469
温柔的废话
温柔的废话 2021-01-11 14:49

I want to split a file containg HTTP response into two files: one containing only HTTP headers, and one containg the body of a message. For this I need to split a file into

4条回答
  •  灰色年华
    2021-01-11 15:18

    You can extract the first part of your file (HTTP headers) with:

    awk '{if($0=="")exit;print}' myFile
    

    and the second part (HTTP body) with:

    awk '{if(body)print;if($0=="")body=1}' myFile
    

提交回复
热议问题