How can I delete every Xth line in a text file?

后端 未结 6 1502
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 05:07

Consider a text file with scientific data, e.g.:

5.787037037037037063e-02 2.048402977658663748e-01
1.157407407407407413e-01 4.021264347118673754e-01
1.736111         


        
6条回答
  •  离开以前
    2020-12-08 05:29

    You could possibly do it with sed, e.g.

    sed -n -e 'p;N;d;' file # print every other line, starting with line 1
    

    If you have GNU sed it's pretty easy

    sed -n -e '0~10p' file # print every 10th line
    sed -n -e '1~2p' file # print every other line starting with line 1
    sed -n -e '0~2p' file # print every other line starting with line 2
    

提交回复
热议问题