What is the command to print out some certain lines of a text file?
What is the command to print out some certain lines of a text file?
am 25.10.2007 03:51:52 von linq936
Hi,
I have an impression some unix command can print some lines of a
file, for example, I want to see on my console the lines between 500
and 520, but I can not remember how to do that.
Any pointer?
Thanks.
Re: What is the command to print out some certain lines of a text file?
am 25.10.2007 04:14:12 von cfajohnson
On 2007-10-25, linq936 wrote:
> I have an impression some unix command can print some lines of a
> file, for example, I want to see on my console the lines between 500
> and 520, but I can not remember how to do that.
sed -n '500,520p' FILENAME
If it's a very large file, you will want to exit after the last
line:
sed -n -e '500,520p' -e '520q' FILENAME
--
Chris F.A. Johnson, author
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Re: What is the command to print out some certain lines of a text file?
am 25.10.2007 04:37:29 von Maxwell Lol
linq936 writes:
> Hi,
> I have an impression some unix command can print some lines of a
> file, for example, I want to see on my console the lines between 500
> and 520, but I can not remember how to do that.
sed -n '500,520p'
or
awk 'NR>=500 && NR<=520'
Re: What is the command to print out some certain lines of a text file?
am 25.10.2007 07:45:55 von ramesh.thangamani
On Oct 25, 7:37 am, Maxwell Lol wrote:
> linq936 writes:
> > Hi,
> > I have an impression some unix command can print some lines of a
> > file, for example, I want to see on my console the lines between 500
> > and 520, but I can not remember how to do that.
>
> sed -n '500,520p'
>
> or
> awk 'NR>=500 && NR<=520'
In case you also need the line numbers also to be printed you can use:
sed -n '500,520{=;p}' | sed 'N;s/\n/:\t/'
Re: What is the command to print out some certain lines of a text file?
am 25.10.2007 10:12:08 von Stephane CHAZELAS
2007-10-24, 22:14(-04), Chris F.A. Johnson:
> On 2007-10-25, linq936 wrote:
>> I have an impression some unix command can print some lines of a
>> file, for example, I want to see on my console the lines between 500
>> and 520, but I can not remember how to do that.
>
> sed -n '500,520p' FILENAME
>
> If it's a very large file, you will want to exit after the last
> line:
>
> sed -n -e '500,520p' -e '520q' FILENAME
or
sed '500,$!d;520q' < FILENAME
or
< FILENAME head -n 520 | tail -n 21
or
awk 'NR >= 500; NR >= 520 {exit}' < FILENAME
--
Stéphane
Re: What is the command to print out some certain lines of a text file?
am 25.10.2007 13:08:48 von gazelle
In article <868x5rzzpy.fsf@localhost.localdomain>,
Maxwell Lol wrote:
>linq936 writes:
>
>> Hi,
>> I have an impression some unix command can print some lines of a
>> file, for example, I want to see on my console the lines between 500
>> and 520, but I can not remember how to do that.
>
> sed -n '500,520p'
>
>or
> awk 'NR>=500 && NR<=520'
ITYM:
awk 'NR==500,NR==520' file
Re: What is the command to print out some certain lines of a text file?
am 25.10.2007 13:55:01 von ramesh.thangamani
On Oct 25, 4:08 pm, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
> In article <868x5rzzpy....@localhost.localdomain>,
> Maxwell Lol wrote:
>
> >linq936 writes:
>
> >> Hi,
> >> I have an impression some unix command can print some lines of a
> >> file, for example, I want to see on my console the lines between 500
> >> and 520, but I can not remember how to do that.
>
> > sed -n '500,520p'
>
> >or
> > awk 'NR>=500 && NR<=520'
>
> ITYM:
>
> awk 'NR==500,NR==520' file
using perl:
perl -nle 'print if 500..520'