Re: sorting files with headers
From: Slowdude (slowdude_at_zerofluid.com)
Date: 01/13/05
- Next message: AlanF: "Re: vi, two characters for a key combo?"
- Previous message: Ed Morton: "Re: simple script Q"
- In reply to: Ed Morton: "Re: sorting files with headers"
- Next in thread: Ed Morton: "Re: sorting files with headers"
- Reply: Ed Morton: "Re: sorting files with headers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
7293 messages
root@zerofluid:/var/adm# time /home/slowdude/bin/trim.sh messages 3 4 > sortfile
real 0m0.082s
user 0m0.020s
sys 0m0.050s
root@zerofluid:/var/adm# time /home/slowdude/bin/trimmorton.sh messages 3 4 > sortfile
real 0m0.092s
user 0m0.070s
sys 0m0.010s
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.
>
> Regards,
>
> Ed.
- Next message: AlanF: "Re: vi, two characters for a key combo?"
- Previous message: Ed Morton: "Re: simple script Q"
- In reply to: Ed Morton: "Re: sorting files with headers"
- Next in thread: Ed Morton: "Re: sorting files with headers"
- Reply: Ed Morton: "Re: sorting files with headers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|