For Programmers: Free Programming Magazines  


Home > Archive > AWK > May 2004 > cutting out some rubbish









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cutting out some rubbish
nhbfluci@rrzn-user.uni-hannover.de

2004-05-03, 1:34 pm

Hi,

I have a file which is in a "standard format" execpt for some
header and footer that I simply want to cut.
That is, want to cut 5 lines at the top and 5 lines
at the bottom of my file.
How to do this with awk ?

Luciano

Stefan Lagotzki

2004-05-03, 1:34 pm

Charles Demas <demas@TheWorld.com>:
> But even simpler is the code I wrote:
> awk '{a[NR]=$0} NR > 5 {print a[NR - 5]}' myfile
> and that only reads the file once.


awk '{a[NR]=$0} NR > 10 {print a[NR - 5]}' myfile

should cut 5 lines at the top and 5 lines at the bottom of
the file:

$ seq 1 1 15 > myfile
$ awk '{a[NR]=$0} NR > 10 {print a[NR - 5]}' myfile
6
7
8
9
10

Stefan

..
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com