sort question

Aldo blinuxman at tuxfamily.org
Tue Jun 24 21:45:49 UTC 2008


On Tue, Jun 24, 2008 at 07:02:07AM -0500, Tim Chase wrote:
> >I'd like to sort, maybe cut, and redirect text lines based on the 3 or 4
> >last chars; is this possible? how?
> 
> One key element you omit is whether the lines are all the same 
> length, or if they have varying lengths.

Yes they variate.

> if they have a ragged right-edge (aren't the same 
> length), you'll need to do a bit more work.

I'll try by using  rev  and  cut  and  uniq  and  sort. 

> If I understand what you're trying to do, you want to isolate the 
> last couple characters in the line, 

Yes, the 3 or 4 latest chars.

>throwing away the rest of the 
> line, sort+unique the remainder, and then dump the results to a 
> file.  

Yes, it is a list of "terminations" in FR I'd like to sort, but also remove
dupes of course:
example there is no need to have 200 times
era
era
era
...

>That could be done with sed and sort:
> 
>   sed 's/.*\(...\)$/\1/' src.txt | sort -u > nodupes.txt
> 
> That should do the last three characters ("...").  If you need 4, 
> just add an extra period.  I used the "-u" functionality of sort 
> which is the same as a basic sort+uniq call (if you need some of 
> uniq's other functionality like counting, you'd have to use it 
> too).  The only caveat is the semi-undefined behavior if a line 
> has less than 3 or 4 characters in it, which this handles, and 
> just treats it as its own thing to be sorted/uniq'ed/output.
> 
> Hope this helps,
> 
Okay, sounds nice, will try it tomorrow.

Many thanx,

Ald0 




More information about the Blinux-list mailing list