home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 15923 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.3 KB  |  33 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!gatech!destroyer!cs.ubc.ca!unixg.ubc.ca!kakwa.ucs.ualberta.ca!atlantis!aaron
  3. From: aaron@atlantis.uucp
  4. Subject: Getting the nth line of a file
  5. Message-ID: <1993Jan25.163208.11697@atlantis.uucp>
  6. Reply-To: aaron%atlantis@kakwa.ucs.ualberta.ca
  7. Organization: Atlantis Communications, Edmonton, AB, Canada
  8. X-Newsreader: TIN [version 1.1 PL8]
  9. Date: Mon, 25 Jan 1993 16:32:08 GMT
  10. Lines: 21
  11.  
  12. Is there an easy, elegant, and quick way to get the Nth line of a file in UNIX?
  13. Or, failing that, in C?
  14.  
  15. Currently I use the simple, but somewhat slow:
  16.  
  17. head -n | tail -1
  18.  
  19. If n is very large(in the problem I'm working on, it's a random number from 1
  20. to ~20000), then this can take several seconds.  Is there a basic UNIX command
  21. I've failed to find in searching the man pages?  Is there something that works
  22. a bit more quickly using ex, or ed?
  23.  
  24. Please email replies, because the feed here is a bit slow.  If your email
  25. bounces(not all mailers like my reply-to), then feel free to post--it'll just
  26. take me a few days to see your message.
  27.  
  28. -- 
  29. ---Alfvaen(Still looking for "October's Baby")
  30. "Clocks don't bring tomorrow--knives don't bring good news."                       ---Bruce Cockburn
  31. Current Album--Genesis:Abacab
  32. Current Read--Sean Russell:The Initiate Brother
  33.