Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.shell Subject: Re: Retaining file permissions Keywords: chmod, sed, awk Message-ID: <1991Feb22.041826.201@athena.mit.edu> Date: 22 Feb 91 04:18:26 GMT References: <6039@ptsfa.PacBell.COM> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 24 In article <6039@ptsfa.PacBell.COM>, jlwestm@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710 Brought to you by Super Global Mega Corp .com