Q: How to preserve date of file when changing it's contents

Q: How to preserve date of file when changing it's contents

Post by Christopher Blenco » Wed, 26 Jul 1995 04:00:00



I have several scripts, to process text files e.g. remove several
lines, modify part of them and so on.

I usually do this in a csh-loop, e.g.

foreach file ($*)
grep -v 'bad_regex' $file > /tmp/$$
mv /tmp/$$ $file
end

Or at least with a few checkings.
I will get the right result, but the original file date will get lost
and all files processed this way will have the date set to the
actual date, because of the redirection and the move command.

I would like to keep the date of the files to the original date,
for this information is more worth then the date I have run the
script on the files.

Is this a simple problem, for I only can think of a kind of
'/ls the date into a textfile, use touch after processing
the old file on the newly created file' procedure ?

Sincerly Christopher

Maybe a C function would be able to do so,
e.g.
main(){

date=...
system(file)
redate(file)

Quote:}

as a rough draw I can imagine off
--
----------------------------------------------------------------------
>                    Christopher Blencowe             _______     <
>>         ||     Pharmazeutisch-Chemisches Institut      | .._.. |   <<
>>>    /  \          Universitaet Heidelberg           |_______|  <<<
>>     /____\                   GERMANY                   /______/    <<


----------------------------------------------------------------------
 
 
 

Q: How to preserve date of file when changing it's contents

Post by Ed Moo » Wed, 26 Jul 1995 04:00:00


: I would like to keep the date of the files to the original date,
: for this information is more worth then the date I have run the
: script on the files.

: Is this a simple problem, for I only can think of a kind of
: '/ls the date into a textfile, use touch after processing
: the old file on the newly created file' procedure ?

It's simple on HP-UX.  I have scripts that

touch -r filename /tmp/timestamp.$$
commands_to_modify_filename
touch -r /tmp/timestamp.$$ filename
rm /tmp/timestamp.$$

I don't know whether -r is a standard option for touch.

 
 
 

Q: How to preserve date of file when changing it's contents

Post by Andreas Schw » Thu, 27 Jul 1995 04:00:00



|> I have several scripts, to process text files e.g. remove several
|> lines, modify part of them and so on.

|> I usually do this in a csh-loop, e.g.

|> foreach file ($*)
|> grep -v 'bad_regex' $file > /tmp/$$
|> mv /tmp/$$ $file
|> end

|> Or at least with a few checkings.
|> I will get the right result, but the original file date will get lost
|> and all files processed this way will have the date set to the
|> actual date, because of the redirection and the move command.

|> I would like to keep the date of the files to the original date,
|> for this information is more worth then the date I have run the
|> script on the files.

Look for the program `cpmod', and use it like this:

foreach file ($*)
grep -v 'bad_regex' $file > /tmp/$$
cpmod $file /tmp/$$
mv /tmp/$$ $file
end

--
Andreas Schwab                                      "And now for something