uniq(1) on last field

Janos Dohanics web at 3dresearch.com
Thu Nov 6 18:30:30 UTC 2014


On Thu, 6 Nov 2014 18:32:50 +0100
Peter Boosten <peter at boosten.org> wrote:

> 
> > 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

I would like to output the entire line as it is in my original post,
and get rid of the repetition of the same file names. So the pseudo
code would be something like:

cat file | uniq -f [n-1]

where n = awk -F "/" '{print NF}'

Is this possible to do with a one-liner?

-- 
Janos Dohanics


More information about the freebsd-questions mailing list