using -t option with unix sort ?
Csaba Henk
csaba-ml at creo.hu
Thu Jul 14 22:11:56 GMT 2005
On Thu, Jul 14, 2005 at 10:47:50AM -0700, Daniel Malaby wrote:
> The sample data has 9 fields, I am trying to sort on the fifth field,
> here is what I have tried.
>
> sort -t\t +4 -5 -o test.txt sample.txt
>
> I did try removing the space and it did not work, I have also tried
> removing the -5. I think the spaces in the third field are confusing sort.
Well, if you are willing to accept a non-orthodox solution,
ruby -e 'puts $<.readlines.sort_by {|x| x.split(/\t/)[4]}' sample.txt > test.txt
will do the job.
I guess there should be a succint way of doing this with perl, too.
Csaba
More information about the freebsd-questions
mailing list