≡ Menu

Shell Script To Delete All Even Numbered Line From a Text File

Shell Script To Delete All Even Numbered Line From a Text File

{ 4 comments… add one }
  • cercatrova January 14, 2010, 12:05 am

    @Kiat Huang

    for some reason your simplified command does not work on my mac. But the following works like a charm.

    for even lines
    sed -e ‘1d;n;d’ yahoo.txt

    for odd lines
    sed -e ‘2d;n;d’ yahoo.txt

  • cercatrova January 13, 2010, 11:44 pm

    @lloyd

    you can do that by

    head -60 file1 >> output.txt | head -60 file2 >> output.txt

  • lloyd April 1, 2009, 5:41 pm

    I want to combine to text file in unix. Both text files have 100 lines each, i want to only take the 1st 60 line from the 1st file and combine it with the 2nd file.

    How do i do that?

  • Kiat Huang September 17, 2008, 10:40 pm

    # This does the same thing quicker and with greater flexibility

    # e.g. delete every 2nd line starting from the 0th line
    sed ‘0~2d’ -i $file

    # e.g. delete every 2nd line starting from the 1st line
    sed ‘1~2d’ -i $file

Security: Are you a robot or human?

Leave a Comment