Need help editing (sed) a file without changing the date of the file.

Need help editing (sed) a file without changing the date of the file.

Post by Jeff Now » Fri, 08 Sep 1995 04:00:00



I would like to be able to run sed on a file to replace
all occurances of one string with another but not have the date
of the file changed.  I think I can use the touch command somehow
but can't figure it out.  I want to run this script on a bunch of
files, actually all the files a directory.  Our path to our home
directory has been changed.  I would like to do

sed s+home/elmer+home+g *

and have all the dates the same and with the change taken place.
I can't figure this out.  I am not a unix programmer so
any help would be appreciated.

Thank you,

Jeff Nowak

 
 
 

1. Need help editing (sed) a file without changing the date of the file.

: I would like to be able to run sed on a file to replace
: all occurances of one string with another but not have the date
: of the file changed.  I think I can use the touch command somehow
: but can't figure it out.  I want to run this script on a bunch of
: files.  Any help would be appreciated.

On my HP-UX system I would...

#!/bin/ksh
for FILE in $*
do
  sed 'your-command-string' $FILE >TMP.$$
  touch -r $FILE TMP.$$
  mv TMP.$$ $FILE
done

This provides no protection; if sed messes up $FILE you don't get a chance
to examine it before replacing it.

2. Problems with Gcc on Red Hat 6.0?????

3. Need help editing file using awk, sed, or whatever it takes...

4. weird ip alias prob

5. Need some advice on checking/editing text files using sed

6. Installing RH6 to Jensen

7. ftp'ng without changing original file date

8. ATM Support and

9. HELP!! edit files use "sed" ..

10. File Permission Changing when user edits file (Samba)

11. Mail Status File with the File Name Changes by Date

12. Archiving files in "date folders" based on date and time file generated

13. Changing permissions on file underlying the mount point without unmounting file system