Re: how to use sed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 08 February 2005 23:57, naxis wrote:
> Sorry to bother you with this but I want to know.
> I tried to use sed to change the perl path of my cgi scripts in a
> directory.
> from /usr/bonsaitools/bin/perl to /usr/bin/perl
> #sed 's/\/usr\/bonsaitools\/bin\/perl/\/usr\/bin\/perl/g' *.cgi
> it didnt work so I changed every thing one by one but I know sed can do
> the job for me.
> can someone teach me that?
> thank you
here is a script I use to do that sort of thing, using sed
you have to write to a new file 


#!/bin/bash
#============================================================================
#
# purpose:  replace a string within a file
#    original file is replaced with updated file
#
# usage:  replace-string oldstring newstring file_name_list
#
#----------------------------------------------------------------------------

tmp=/tmp/replace$$

if [ $# -lt 3 ]; then
 echo "usage:  $(basename $0) oldstring newstring file_name_list"
 exit 1
fi

oldstring=$1
newstring=$2
shift 2
for file in $*
do
 if [ -w $file ]; then
  sed "s/$oldstring/$newstring/g" $file > $tmp
  mv $tmp $file
 else
  echo "$file not writable"
 fi
done

rm -r $tmp
#============================================================================

modify it as needed.  enjoy.

paul
-- 
Paul F. Almquist
paul@xxxxxxxxxxxxx
Eau Claire, WI  USA


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux