Re:SCRIPT: head

From: Jean Buchet (jean.buchet@libertysurf.fr)
Date: Tue Nov 07 2000 - 22:57:49 CET


Jochen,
You can make your script tinier :
#/bin/ash
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

#/bin/ash
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

regards
Jean

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

---------------------------------------------------------------------
To unsubscribe, e-mail: mulinux-unsubscribe@sunsite.auc.dk
For additional commands, e-mail: mulinux-help@sunsite.auc.dk



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