Date: Thu, 6 Nov 2014 13:29:41 -0500 From: Janos Dohanics <web@3dresearch.com> To: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: uniq(1) on last field Message-ID: <20141106132941.cc33fc02635648cf537885a1@3dresearch.com> In-Reply-To: <33AF1AA1-9768-4D65-86A7-88A307AEFA5C@boosten.org> References: <20141106110319.eb34eaa069a4881824072010@3dresearch.com> <C1660725-BF36-4F5F-9BA3-4E0231DB17A0@boosten.org> <33AF1AA1-9768-4D65-86A7-88A307AEFA5C@boosten.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 6 Nov 2014 18:32:50 +0100 Peter Boosten <peter@boosten.org> wrote: > > > On 6 nov. 2014, at 17:42, Peter Boosten <peter@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20141106132941.cc33fc02635648cf537885a1>