Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2002
    Posts
    30

    Question Unanswered: Print from Last Bottom Line to First Line ?

    Hi All

    IF there are 10 lines in a file i.e from line 1-10. I would like read the file and print from bottom line i.e line 10 to 1 in a new file ?

    Can anybody have an idea about how to do it ?

    Thank You
    Vikram

  2. #2
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525

    Re: Print from Last Bottom Line to First Line ?

    Originally posted by bollin99
    Hi All

    IF there are 10 lines in a file i.e from line 1-10. I would like read the file and print from bottom line i.e line 10 to 1 in a new file ?

    Can anybody have an idea about how to do it ?

    Thank You
    Vikram
    Use awk...

    awk '{line[NR]=$0}END{for(i=NR;i>0;i--){print line[i]}}' yourFile > newFile

    or sed...

    sed '1!G;h;$!d' yourFile > newFile

    or if you're lucky, you might have 'tac' installed...

    tac yourFile > newFile

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    And then you could do it like this...

    cat -n yourFile | sort -nr | cut -f2 > newFile

    If you want any explanation of these examples, just ask!

  4. #4
    Join Date
    Sep 2002
    Posts
    30

    Thanks a lot. it worked

    Originally posted by Damian Ibbotson
    And then you could do it like this...

    cat -n yourFile | sort -nr | cut -f2 > newFile

    If you want any explanation of these examples, just ask!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •