On Wed, Jan 09, 2008 at 11:40:37PM -0600, Mike Miller wrote:
> On Wed, 9 Jan 2008, Florin Iucha wrote:
> 
> > And the Oscar goes to:
> >
> > find /some/dir -type f -printf "%h/%f %T@\n" | awk '{ if ($2 > the_max) { the_max = $2; file_name = $1; } }
> > END { print file_name }'
> >
> > I would like to thank Google for its search engine and to the find man 
> > page for its thorough description of the million options and switches...
> 
> 
> This is the stuff I like most on LUG lists -- learning all the cool tricks 
> with GNU/UNIX/Linux commands.  So much can be done but it takes years to 
> learn all the efficient ways of doing things.  I've used awk/gawk a 
> gazillion times but only in a few ways, so using it to find a maximum was 
> not in my repertoire, but that is an excellent idea.  I always would have 
> sorted the file even though I knew that couldn't be the best way to go.
> 
> That said, there are still some problems with the one-liner above.  First 
> and foremost, if any file in the tree contains a space in the filename, 
> the command will fail.  At first I was going to say that the problem is in 
> the printf argument because it doesn't uses a space as delimiter between 
> the file name and date stamp:
> 
> $ find . -type f -printf "%h/%f %T@\n"
> ./Lee, Alvin - I'm Going Home.txt 1182200822
> ./0_TABLATURE_EXPLANATION.txt 1118104853
> ./Semisonic - FNT.txt 1153491460
> ./Animals - House of the Rising Sun.tab.txt 1142214281
> [snip]
> 
> But maybe it is better to say that the problem is with the awk command. 
> If we replace $2 with $NF and replace $1 with $0, we get this:

We can switch the arguments around and use a less likely separator
(warning, untested):

find /some/dir -type f -printf "%T@^%h/%f\n" | awk -F^ '{ if ($1 > the_max) { the_max = $1; file_name = $2; } }
END { print file_name }'

Cheers,
florin

-- 
Bruce Schneier expects the Spanish Inquisition.
      http://geekz.co.uk/schneierfacts/fact/163
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20080110/49fd1bca/attachment.pgp