Re: sorting files with headers
From: Slowdude (slowdude_at_zerofluid.com)
Date: Thu, 13 Jan 2005 00:06:17 GMT
> This approach would be more efficient:
You should test for efficiency before making that claim. The numbers went
back and forth, but they are nearly the same.
trim.sh is mine
trimmorton is yours
root@zerofluid:/var/adm# wc -l messages
root@zerofluid:/var/adm# time /home/slowdude/bin/trim.sh messages 3 4 > sortfile
root@zerofluid:/var/adm# time /home/slowdude/bin/trimmorton.sh messages 3 4 > sortfile
It is a wash and my version is easier to read.
> len=$(wc -l < "$1")
> awk -vhd="$2" -vtl="$((len + 1 - $3))" 'NR>hd && NR<tl' "$1"
> If you don't like or don't have access to "wc", then there's various
> ways to do it just using awk, but they all require parsing the input
> file twice.