![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strange behaviour from script in crontab | PilotGoose | Shell Programming and Scripting | 1 | 06-26-2008 09:54 AM |
| Help with my weird script! | kdyzsa | Shell Programming and Scripting | 1 | 06-15-2008 10:39 PM |
| Weird sudo behaviour | geomonap | UNIX for Advanced & Expert Users | 1 | 02-03-2006 05:08 PM |
| any explanation for thsi shell script behaviour | xiamin | Shell Programming and Scripting | 9 | 11-09-2001 01:13 PM |
| Weird script | Duckman | UNIX for Dummies Questions & Answers | 2 | 03-14-2001 01:53 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Weird sed behaviour in script
I've written a small script to replace certain words in all the the files in a directory.
Code:
#!/bin/sh #Get list of files to be edited file_list=`ls -p` for i in $file_list do echo "Processing $i" alteredi=`echo "$i" | sed -e 's/\//d/'` if [ $i = $alteredi ] then if [ $i != "maketest" ] then #actual altering 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 echo " $i has been altered" else echo " Not altering myself" fi else echo " Not altering directories" fi done When I cat a large text file the entire file gets printed on my screen. Thanks in advance. |
|
||||
|
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 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" Code:
sed -i -e "s/login\//login.tst\//" -e "s/cyberkd\//cyberkd.tst\//" -e "s/\/db_connect.inc.php/\/testdb_connect.inc.php/" "$1" Last edited by Franklin52; 08-30-2008 at 07:52 AM.. |
|
||||
|
Thank you. It works!
|
| Sponsored Links | ||
|
|