Retaining file permissions
Jonathan I. Kamens
jik at athena.mit.edu
Fri Feb 22 15:18:26 AEST 1991
In article <6039 at ptsfa.PacBell.COM>, jlwestm at PacBell.COM (Jeff Westman) writes:
|> # Replace one occurance with another
|>
|> print "Enter a \"from\" string: \c" ; read FROM
|> print "Enter a \"to\" string: \c" ; read TO
|>
|> sed s/$FROM/$TO/gp $i > xyzyx
|> mv -f xyzyx $i
Tom Christiansen has already posted a perl version, but (believe it or not
:-) it is possible to do it without perl (although perhaps not in one
process). If you don't have perl installed, you can probably get what you
want by using "cp" in the last line instead of "mv", since cp attempts to keep
file permissions on existing files (although it won't be able to keep setuid
bits; then again, neither will perl).
Tom's probably right that you want to change the "gp" in the sed command to
"g". You probably also want to change "occurance" to "occurrence" :-).
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.shell
mailing list