![]() |
|
|
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 |
| Need shell/sed script for grep+string replacement | pranavagarwal | Shell Programming and Scripting | 3 | 11-15-2007 06:35 AM |
| String Replacement with Perl | Lindarella | Shell Programming and Scripting | 4 | 09-29-2006 03:05 PM |
| sed problem - replacement string should be same length as matching string. | amangeles | Shell Programming and Scripting | 4 | 01-11-2006 06:11 AM |
| Replacement using sed | handak9 | UNIX for Dummies Questions & Answers | 5 | 07-13-2004 12:28 PM |
| String replacement in multiple files | WABonnett | Shell Programming and Scripting | 2 | 02-17-2004 03:49 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
String Replacement Script
Okay, I have a script right now that is made to search through a file and replace certain strings with a new one. The format to execute is "/subst <replacethis> <withthis> <filename>" and it only updates the file IF changes are made (in order to preserve the time it was made/last modified). I have this working 100% right now, but the next step is to edit the script so that it is possible for users to do "/subst <replacethis> <withthis> <filename> <filename2> <filename3> <filenamex>" as high as they want. If anyone can point me in the right direction of methods to do this or simply fix it for me, I would be very greatful. Here is my current script: Code:
#!/bin/bash replacethis=$1 withthis=$2 file=$3 sed -e "s+$replacethis+$withthis+g" $file > $file.bak cmp $file $file.bak > /dev/null if [ $? -eq 0 ] then echo "Files are the same, nothing was replaced." rm $file.bak else mv $file.bak $file fi Thanks in advance for anyone that can help! |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|