Randomly Pick Lines From a File Without Slurping It With Unix

前端 未结 10 939
忘了有多久
忘了有多久 2020-12-07 11:40

I have a 10^7 lines file, in which I want to choose 1/100 of lines randomly from the file. This is the AWK code I have, but it slurps all the file content before hand. My PC

10条回答
  •  感情败类
    2020-12-07 11:50

    This should work on most any GNU/Linux machine.

    $ shuf -n $(( $(wc -l < $file) / 100)) $file
    

    I'd be surprised if memory management was done inappropriately by the GNU shuf command.

提交回复
热议问题