Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Linux command to extract first xxx lines from file

Options
  • 06-07-2006 3:02pm
    #1
    Registered Users Posts: 90 ✭✭


    Hi, I was wondering if someone could tell me how to go about getting say the first 50,000 lines from a file and write it to another file in linux. I guess it's pretty simple but I googled it and didn't find anything. Thanks


Comments

  • Registered Users Posts: 7,588 ✭✭✭Bluetonic


    head -n 50000 from.file > to.file


  • Closed Accounts Posts: 9,273 ✭✭✭Morlar


    (already answered).


  • Registered Users Posts: 90 ✭✭Alligator Wine


    Just as I thought, easypeasy, cheers


  • Registered Users Posts: 27,163 ✭✭✭✭GreeBo


    or if its (g)zipped
    gzcat from.file | head -50000 > to.file

    a little routine that I use all the time when parsing log files is
    grep -n <search term> myfile

    then you get the line number you want, say its on line 1000
    usually I want something a bit before and a bit after the line I grepped for
    so then you can do
    head -1100 | tail -200 > result.log

    now result.log contains 200 lines with the bit you searched for in the middle

    Now wheres my BluePeter badge?
    :D


Advertisement