美文网首页
Perl 分割文本文件

Perl 分割文本文件

作者: 千羽之城88 | 来源:发表于2020-12-08 15:29 被阅读0次

    # test1
    123
    123

    # test2
    ...
    # test10
    123
    123

    分割代码:

    perl -E 'while(<>){if(/^# \[/){++$i;  open $out,">","File$i.out" or die $!; select $out}; print $_ if $out}' temp1
    
    ####
    ls -rt *.out
    
    File1.out  File2.out  File3.out  File4.out  File5.out  File6.out  File7.out  File8.out  File9.out  File10.out
    

    gawk 方法

    gawk '{print $0>(($0 ~ /^# \[/) ? ++i".out" : i".out")}' temp1
    

    相关文章

      网友评论

          本文标题:Perl 分割文本文件

          本文链接:https://www.haomeiwen.com/subject/nttqgktx.html