Split file by vector of line numbers

前端 未结 5 1666
礼貌的吻别
礼貌的吻别 2021-01-27 03:41

I have a large file, about 10GB. I have a vector of line numbers which I would like to use to split the file. Ideally I would like to accomplish this using command-line utilitie

5条回答
  •  暖寄归人
    2021-01-27 04:04

    Here is a little awk that does the trick for you:

    awk -v v="2 5" 'BEGIN{v=" 1 "v" "}
                    index(v," "FNR" ") { close(f); f=FILENAME "." (++i) }
                    { print > f }' file
    

    This will create files of the form: file.1, file.2, file.3, ...

提交回复
热议问题