remove all lines from a text file starting at first empty line

前端 未结 5 1044
一生所求
一生所求 2020-12-18 16:17

What is the best way to remove all lines from a text file starting at first empty line in Bash? External tools (awk, sed...) can be used!

Example

1:          


        
5条回答
  •  一个人的身影
    2020-12-18 16:45

    With AWK:

    $ awk '/^$/{exit} 1' test.txt > output.txt
    

    Contents of output.txt

    $ cat output.txt 
    ABC
    DEF
    

    Walkthrough: For lines that matches ^$ (start-of-line, end-of-line), exit (the whole script). For all lines, print the whole line -- of course, we won't get to this part after a line has made us exit.

提交回复
热议问题