How to split a file and keep the first line in each of the pieces?

前端 未结 12 784
-上瘾入骨i
-上瘾入骨i 2020-12-07 18:28

Given: One big text-data file (e.g. CSV format) with a \'special\' first line (e.g., field names).

Wanted: An equivalent of the cor

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 18:59

    I liked the awk version of marco, adopted from this a simplified one-liner where you can easily specify the split fraction as granular as you want:

    awk 'NR==1{print $0 > FILENAME ".split1";  print $0 > FILENAME ".split2";} NR>1{if (NR % 10 > 5) print $0 >> FILENAME ".split1"; else print $0 >> FILENAME ".split2"}' file
    

提交回复
热议问题