Find the answer to your Linux question:
Results 1 to 4 of 4
Hi How can I replace the first line in a file with the last line, (consider that I dont the line number too) >cat hello.txt First Line 1 25 53 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2

    Post How to replace last line with first line in VI editor ??


    Hi

    How can I replace the first line in a file with the last line, (consider that I dont the line number too)

    >cat hello.txt
    First Line
    1
    25
    53
    Last Line

    >[/hello.txt]

    The output needs to below one :

    >cat hello.txt
    Last Line
    1
    25
    53
    First Line

    >[/hello.txt]

    Eagerly waiting for answer,,

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,864
    Surely you're not just putting the last line first, but you're swapping the first and last lines. The simple answer is to use gedit and cut and paste the lines.

    If you're struggling to do this for your homework, then perhaps you should ask your tutor or teacher rather than ask us to do your homework for you?
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Just Joined!
    Join Date
    Jul 2011
    Posts
    2
    Thanks for your suggestions..
    It was an interview question, even i too replied your same answer.. But, they asked me to exclude this option (gedit -> cut & Paste )...
    They asked me to give a command for doing this swapping in VI...
    Even though I am RHCE along with Oracle certified Weblogic System Engineer, but some time silly QA like this block me ...

  4. #4
    Linux Guru
    Join Date
    Oct 2007
    Location
    Tucson AZ
    Posts
    3,190
    Check the section Editing Blocks of Text at this site:

    The Vim commands cheat sheet

    I haven't tested it so...?

Posting Permissions

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