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

前端 未结 4 460
温柔的废话
温柔的废话 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条回答
  •  Happy的楠姐
    2021-01-11 15:15

    $ cat test.txt
    a
    b
    c
    
    d
    e
    f
    $ sed '/^$/q' test.txt 
    a
    b
    c
    
    $ sed '1,/^$/d' test.txt 
    d
    e
    f
    

    Change the /^$/ to /^\s*$/ if you expect there may be whitespace on the blank line.

提交回复
热议问题