Re: Bash/Zsh-script: Reading a particular line from a file?



On 21 Dec 2006 09:30:54 -0800, Koppe74 staggered into the Black Sun and
said:
Whenever I've needed a paticular line from a file I've always managed
to get by by piping together 'head' and 'tail' or using 'sed' I was
wondering if there are some built-ins for the shell -- or perhaps a
option for cat -- that would allow me to read a particular line of a
file (e.g. something like "my-file.txt{8]" to specify line 8 of the
file "my-file").

Not shell, but:

#!/usr/bin/perl -w
open(IFP,"test.txt") or die "could not open test.txt: $!";
@lines=<IFP>;
# NOTE: If test.txt is a 930,000 line file, you'll eat a metric
# arseload of memory. Caveat programmer.
print "42nd line is ".$lines[41];
# end perl script

....you can probably do something similar in Python. A quick read
through the info pages says that you'd get line N from a file in a shell
programming context with head and tail, or awk, or sed. TMTOWTDI, pick
the one that works best. HTH,

--
One RAID to rule them all, One RAID to bind them
One RAID to hold the files and in the darkness grind them
In the land of Server where the Unix lies....
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
.



Relevant Pages

  • Re: Lobster Tails
    ... I dont' remember "slitting" the shell, just run a sharp knife along ... the edges and pop out the meat ... it's regular broiler height and you eyeball ... Too late now, I'm sure, but we would slit the top side of the tail, place ...
    (rec.food.cooking)
  • See My New Portable Crappy Rehearsal Kit
    ... With a good head, it'll probably sound good. ... I mounted a cymbal arm mount on the floor tom shell, ...
    (rec.music.makers.percussion)
  • Re: See My New Portable Crappy Rehearsal Kit
    ... With a good head, it'll probably sound good. ... I mounted a cymbal arm mount on the floor tom shell, ...
    (rec.music.makers.percussion)
  • Re: Reskinning Was - Re: Making drumheads from goat hides?
    ... If you can get yellow carpenter's glue, it's the easiest to work with, but epoxy will work too. ... Cut 2 circles the size of the shell you want or find a cylindrical something that is the right diameter. ... Easiest way of attaching the head to the shell is furniture nails, which are those ornamental round headed nails like you see on old sofas. ...
    (rec.music.makers.builders)
  • missing libncurses.so.5 and other lib*
    ... rather a blackout in my head. ... and other messages, all concerning lib**. ... /ports/graphics/xnview was complaining about a stale dependancy. ... tried the emergency shell from a 5.1 disk, but I am uncertain what to do ...
    (freebsd-current)