Splitting large text file on every blank line

后端 未结 9 954
南方客
南方客 2020-12-05 07:53

I\'m having a bit trouble of splitting a large text file into multiple smaller ones. Syntax of my text file is the following:



        
9条回答
  •  天涯浪人
    2020-12-05 08:34

    In case you get "too many open files" error as follows...

    awk: whatever-18.txt makes too many open files
     input record number 18, file file.txt
     source line number 1
    

    You may need to close newly created file, before creating a new one, as follows.

    awk -v RS= '{close("whatever-" i ".txt"); i++}{print > ("whatever-" i ".txt")}' file.txt
    

提交回复
热议问题