Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C Shell Date Loop

Status
Not open for further replies.

SpongeBob1

Programmer
Mar 1, 2002
49
US
Hi,

I'm currently writing a loop which must sort date stamped files by date e.g. file.052802.log, does anyone know how to do this? I need to use the C Shell.

Thanks in advance.
 
if the files were created by the date in the file, it would be better to let the ls command do the work for you. Something like:
Code:
ls -rt file.*.log
that will output the files from oldest to most recent.

You could put this in a loop in your shell script like this: (sorry my syntax is Ksh)
Code:
for fn in `ls -rt file.*.log`; do
  echo "$fn is being processed"
done

I haven't used C-shell in years. I can't remember the syntax for a for loop, but this should point you in the right direction. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
Hi,

Here is the CSH equivelent to the above.

foreach fn ( `ls -rt file.*.log` )
echo "$fn is being processed"
.
.
.
end



if you are going to being sorting dated files you might consider changing the name of the files to make it easier to sort simply by the file name.

file.yyyymmdd.log

then you can simply do

foreach fn ( file.*.log )
echo "$fn is being processed"
.
.
.
end

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top