Jan 19, 2006 #1 kobewins Programmer Dec 1, 2005 57 US I have a huge file (about 25 millions lines). Is this a way to read Line n directly, without looping througth each line of the file? Any ideas are appreciated. David
I have a huge file (about 25 millions lines). Is this a way to read Line n directly, without looping througth each line of the file? Any ideas are appreciated. David
Jan 19, 2006 #2 columb IS-IT--Management Feb 5, 2004 1,231 EU Use head and then tail. So to get line 250 Code: head -250 bigfile | tail -1 Columb Healy Upvote 0 Downvote
Jan 19, 2006 #3 columb IS-IT--Management Feb 5, 2004 1,231 EU Of course you could always use Code: awk 'NR=250 {print}' bigfile Columb Healy Upvote 0 Downvote
Jan 19, 2006 #4 columb IS-IT--Management Feb 5, 2004 1,231 EU Oops Spot the mistake in the awk example should have been Code: awk 'NR==250{print}' bigfile Columb Healy Upvote 0 Downvote
Oops Spot the mistake in the awk example should have been Code: awk 'NR==250{print}' bigfile Columb Healy
Jan 19, 2006 Thread starter #5 kobewins Programmer Dec 1, 2005 57 US Thanks alot for ALL. David Upvote 0 Downvote
Jan 19, 2006 #6 SamBones Programmer Aug 8, 2002 3,186 US Also... Code: sed -n '250p' bigfile Upvote 0 Downvote
Jan 19, 2006 1 #7 p5wizard IS-IT--Management Apr 18, 2005 3,165 BE sed -n '250p;q' bigfile this would end faster I believe, without having to read the whole file. HTH, p5wizard Upvote 0 Downvote
sed -n '250p;q' bigfile this would end faster I believe, without having to read the whole file. HTH, p5wizard
Jan 19, 2006 #8 p5wizard IS-IT--Management Apr 18, 2005 3,165 BE make that sed -n '250p;251q' bigfile or sed '250q;d' bigfile google for sed oneliners and take your pick... HTH, p5wizard Upvote 0 Downvote
make that sed -n '250p;251q' bigfile or sed '250q;d' bigfile google for sed oneliners and take your pick... HTH, p5wizard
Jan 20, 2006 #9 feherke Programmer Aug 5, 2002 9,541 RO Hi Good point, p5wizard, I should think to such optimization too. Just as a third way to implement your suggestion : Code: sed -n '250{;p;q;}' Feherke. http://rootshell.be/~feherke/ Upvote 0 Downvote
Hi Good point, p5wizard, I should think to such optimization too. Just as a third way to implement your suggestion : Code: sed -n '250{;p;q;}' Feherke. http://rootshell.be/~feherke/
Jan 25, 2006 #10 Annihilannic MIS Jun 22, 2000 6,317 AU Or a similar optimisation for awk Code: awk 'NR==250{print;exit}' bigfile Annihilannic. Upvote 0 Downvote