The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-30-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Don't read and write to the same file and using cat with sed is redundant, replace these lines:

Code:
cat $i | sed -e "s/login\//login.tst\//" > $i
cat $i | sed -e "s/cyberkd\//cyberkd.tst\//" > $i
cat $i | sed -e "s/\/db_connect.inc.php/\/testdb_connect.inc.php/" > $i
with:

Code:
sed -e "s/login\//login.tst\//" -e "s/cyberkd\//cyberkd.tst\//" -e "s/\/db_connect.inc.php/\/testdb_connect.inc.php/" "$1" > temp.file
mv temp.file "$1"
If you're sed version supports the -i flag you can edit the file in place without using a temporary file.

Code:
sed -i -e "s/login\//login.tst\//" -e "s/cyberkd\//cyberkd.tst\//" -e "s/\/db_connect.inc.php/\/testdb_connect.inc.php/" "$1"
Regards

Last edited by Franklin52; 08-30-2008 at 07:52 AM..