| Author |
Comparing age of directories
|
|
| gump33lt 2004-03-19, 8:24 pm |
| 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
| |
| Ed Morton 2004-03-19, 8:24 pm |
|
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
| |
| John DuBois 2004-03-19, 8:24 pm |
| 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/
| |
| gump33lt 2004-03-19, 8:24 pm |
| 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>...[color=darkred]
> gump33lt wrote:
>
> Try "ls -t".
>
> Ed.
>
| |
| Ed Morton 2004-03-19, 8:24 pm |
|
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.
|
|
|
|