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

前端 未结 5 1035
一生所求
一生所求 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:46

    Perl version

     perl -e '
            open $fh, ">","stuff";  
            open $efh, ">", "rest_of_stuff"; 
            while(<>){
               if ($_ !~ /\w+/){
                     $fh=$efh;
               } 
               print $fh $_;
             }
                ' demo
    

    This creates two output files and iterates over the demo data. When it hits a blank line, it flips the output from one file to the other.

    Creates

    stuff:

    ABC
    DEF
    

    rest_of_stuff:

    
    GHI
    

提交回复
热议问题