uniq(1) on last field

Peter Boosten peter at boosten.org
Thu Nov 6 17:56:00 UTC 2014


> On 6 nov. 2014, at 17:42, Peter Boosten <peter at boosten.org> wrote:
> 
> 
>> 
>> 
>> I would like to use uniq(1) on the file name, which is of course the
>> last field if / is used as field separator. 
>> 
>> How can I tell uniq(1) the "last field" if I have variable number of
>> fields?
> 
> 
> sort -u might be a better option
> 

Ah, I missed the ‘variable number of fields’…

What is it you’re trying to show? Since the line in itself always is unique. If you only want to show the file name, you could use awk ‘{print $NF}’ to show the last field, end pipe that through uniq.

so:

awk ‘{print $NF}’ file | uniq (-c if you want to count them)

I don’t think either uniq nor sort have any notion of 'last field’ in a variable field situation. 

-- 
Peter Boosten







More information about the freebsd-questions mailing list