Delete lines from file with SED or AWK

前端 未结 3 847
旧时难觅i
旧时难觅i 2020-12-09 04:57

Ive seen many variations, very confused on how to solve these 3 problems.

  1. deleting all rows except the first from a file
  2. deleting a row from file with
3条回答
  •  渐次进展
    2020-12-09 05:35

    Using sed:

    Delete 1st line:

    sed '1d' file-name
    

    Delete 10th line:

    sed '10d' file-name
    

    Delete line # 5 to 10

    sed '5,10d' file-name
    

    All above sed commands will write output on stdout that you can redirect to another file if you want or use -i flag of sed to inline edit the file.

提交回复
热议问题