help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to translate one file


From: Eric Blake
Subject: Re: [Help-bash] how to translate one file
Date: Tue, 03 Jan 2012 08:51:43 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111222 Thunderbird/9.0

On 01/03/2012 08:32 AM, lina wrote:
> sed -f dict.txt lastline.txt | sed 's/.\(.*\)/\1/' | sed -e 's/[ ]*//' |
> sort -n -k2 -n -k3 -n -k4 -n -k5 -n -k6 -n -k7 -n -k8 -n -k9 -n -k10 -n

Your use of sort is suspicious.  If you are using GNU coreutils, try
adding --debug to get some useful feedback.  In particular, -n is
global, so specifying it more than once is pointless.  Meanwhile, use of
-k with only a single endpoint is almost always wrong; you almost always
want to list both a start and end point, as in -k2,2.

I would have written this as:

sort -n -k2,2 -k3,3 -k4,4 -k5,5 ...

> -k11 -n -k12 -n -k13 -n -k14 -n -k15 -n -k16 -n -k17 -n -k18 -n -k19 -n
> -k20 -n -k21 -n -k22 -n -k23 -n -k24 -n -k25 -n -k26 -n -k27 -n -k28 -n
> -k29 -n -k30 -n -k31 -n -k32 -n -k33 -n -k34 -n -k35 -n -k36 -n -k37 -n
> -k38 -n -k39 -n -k40 -n -k41 -n -k42 | sed 's/[ ]*//' >> a.out

Your pipeline has a sed 's/[ ]*//' both before and after the sort; since
the first one already filtered things, the last one is a pointless waste
of CPU cycles.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]