Re: Bash/Zsh-script: Reading a particular line from a file?
- From: Dances With Crows <danSPANceswitTRAPhcrows@xxxxxxxxx>
- Date: Thu, 21 Dec 2006 12:15:55 -0600
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
.
- Follow-Ups:
- Re: Bash/Zsh-script: Reading a particular line from a file?
- From: Anonymous
- Re: Bash/Zsh-script: Reading a particular line from a file?
- From: Frank Stutzman
- Re: Bash/Zsh-script: Reading a particular line from a file?
- References:
- Bash/Zsh-script: Reading a particular line from a file?
- From: Koppe74
- Bash/Zsh-script: Reading a particular line from a file?
- Prev by Date: Re: NEWBIE wants older LINUX for learning the basics
- Next by Date: Re: swap size for 2gb 2 processors?
- Previous by thread: Bash/Zsh-script: Reading a particular line from a file?
- Next by thread: Re: Bash/Zsh-script: Reading a particular line from a file?
- Index(es):
Relevant Pages
|