Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on How to print a random line from a huge file? within the PERL forums, part of the Web Development category; Hi there, Say I have a text file of huge size, say 1G (?), and I want to print a random line from that file. The way I was thinking ...
|
|||||||
| PERL PERL Scripts - Tips, Tricks, Issues, Latest News, PERL Resource and PERL related topics can be discussed in this forum. |
![]() |
| LinkBack | Thread Tools | Display Modes |
|
|||
|
How to print a random line from a huge file?
Hi there,
Say I have a text file of huge size, say 1G (?), and I want to print a random line from that file. The way I was thinking of is: 1. run a while loop where I can get the total line number of that file. 2. call the random function by giving the range of that total line number. 3. run the while loop for the second time to print out that random line. But it is really costly! Is there a much better, more efficient way to do that. Thanks, Charlie, |
| Sponsored Links |
|
|||
|
Re: How to print a random line from a huge file?
Try to call unix command thro perl using system command .
You can count the line if you want. If you want print any line use sed -n command , this is simple. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to read line by line from a file in C | rohit_tayal06 | C and C++ | 2 | 07-29-2008 04:21 AM |
| How to match multiline when reading input file line by line | vishwaRam | PERL | 1 | 02-07-2008 08:35 AM |
| Writing flat file line by line | venkat_doda | WinRunner | 1 | 12-10-2007 06:51 AM |
| How to replace particular region only and print all content as a output file. | vishwaRam | PERL | 0 | 10-29-2007 03:59 AM |
| Append the result of another shell script to the last line of a file | swaroopa | Unix/Linux | 1 | 06-26-2007 05:29 PM |