Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Comparing age of directories
I have a requirement to parse data in a file that is in a directory
whose name is entirely numeric (e.g. 1078772406534).  My issue is that
the numerically named directory is in a directory consisting of a
number of other directories, one of which also has an entirely numeric
name (e.g. 1079007041802).  I am looking for an elegant way to
determine which of these two directories has been modified most
recently as that is the directory in which resides the file I wish to
parse.  Both of the numeric directories contain the same list of files
and subdirectories.

I am currently trying to determine this using regular shell scripting
and a find command but it's rather cumbersome and I haven't hit upon a
solution.  I'm figuring there must be a very simple way to make this
determination.

Any help is appreciated.

Larry

Report this thread to moderator Post Follow-up to this message
Old Post
gump33lt
03-20-04 01:24 AM


Re: Comparing age of directories

gump33lt wrote:
> I have a requirement to parse data in a file that is in a directory
> whose name is entirely numeric (e.g. 1078772406534).  My issue is that
> the numerically named directory is in a directory consisting of a
> number of other directories, one of which also has an entirely numeric
> name (e.g. 1079007041802).  I am looking for an elegant way to
> determine which of these two directories has been modified most
> recently as that is the directory in which resides the file I wish to
> parse.  Both of the numeric directories contain the same list of files
> and subdirectories.
>
> I am currently trying to determine this using regular shell scripting
> and a find command but it's rather cumbersome and I haven't hit upon a
> solution.  I'm figuring there must be a very simple way to make this
> determination.

Try "ls -t".

Ed.

> Any help is appreciated.
>
> Larry


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-20-04 01:24 AM


Re: Comparing age of directories
In article <b842aadf.0403110501.2f73cbb3@posting.google.com>,
gump33lt <gump33lt@netscape.net> wrote:
>I have a requirement to parse data in a file that is in a directory
>whose name is entirely numeric (e.g. 1078772406534).  My issue is that
>the numerically named directory is in a directory consisting of a
>number of other directories, one of which also has an entirely numeric
>name (e.g. 1079007041802).  I am looking for an elegant way to
>determine which of these two directories has been modified most
>recently as that is the directory in which resides the file I wish to
>parse.  Both of the numeric directories contain the same list of files
>and subdirectories.
>
>I am currently trying to determine this using regular shell scripting
>and a find command but it's rather cumbersome and I haven't hit upon a
>solution.  I'm figuring there must be a very simple way to make this
>determination.

If you use a POSIX shell:

[[ $dir1 -nt $dir2 ]] && print "$dir1 is newer than $dir2"

John
--
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/

Report this thread to moderator Post Follow-up to this message
Old Post
John DuBois
03-20-04 01:24 AM


Re: Comparing age of directories
Thanks for that!  I ended up using:

NUMDIR=`ls -1td [1-9]*|awk '{if (NR == 1) {print $1}}'`

Larry

Ed Morton <morton@lsupcaemnt.com> wrote in message news:<WIudnRKxKPuQ9s3dRVn-vw@comcast.com
>...
> gump33lt wrote: 
>
> Try "ls -t".
>
> 	Ed.
> 

Report this thread to moderator Post Follow-up to this message
Old Post
gump33lt
03-20-04 01:24 AM


Re: Comparing age of directories

gump33lt wrote:
> Thanks for that!  I ended up using:
>
> NUMDIR=`ls -1td [1-9]*|awk '{if (NR == 1) {print $1}}'`

The more awk-ish syntax would be:

NUMDIR=`ls -1td [1-9]*|awk 'NR == 1 {print $1}'`

but that's still going through every record, whereas you want to stop
after the first one, so you'd add an exit:

NUMDIR=`ls -1td [1-9]*|awk 'NR == 1 {print $1; exit}'`

but since you just want to print the first one then exit, you don't need
to test NR, so you'd just do:

NUMDIR=`ls -1td [1-9]*|awk '{print $1; exit}'`

but there's another UNIX tool called "head" that does this by design, so
you'd really drop awk all together and just do:

NUMDIR=`ls -1td [1-9]*|head -1`

And now I get flamed for suggesting a non-awk solution in an awk NG,
sigh.....

Regards,

Ed.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
03-20-04 01:24 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 11:34 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.