Re:SCRIPT: head

From: Jean Buchet (
Date: Tue Nov 07 2000 - 22:57:49 CET

You can make your script tinier :
awk -v max=$2 '
        { if (NR < ((max=="")?10:(max<0)?-1*max:max)) print $0; }' $1

NR is the number of records read so far.

I can't remeber (haven't practiced for several months) if you can put boolean statements in the select clause. If awk permits it, then your mu-head command becomes

awk -v max=$2 '(NR<((max=="")?10:(max<0)?-1*max:max)) { print $0 }' $1

With Michele's advice, it could be something like
#/bin/awk -f
(NR<max=((argv[2]=="")?10:(argv[2]<0)?-1*argv[2]:argv[2])) { print $0 }

I haven't tested it yet (hard disk failure), I'll have to use a boot floppy


>I like small scripts... for mu
Small is beautiful!

To unsubscribe, e-mail:
For additional commands, e-mail:

This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:16 CET