![]() |
|
|
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 |
| how can search a String in one text file and replace the whole line in another file | kkraja | UNIX for Dummies Questions & Answers | 6 | 08-06-2008 08:23 AM |
| How to replace the string in unix file? | param_it | UNIX for Dummies Questions & Answers | 5 | 06-26-2007 10:06 AM |
| replace a string with content from another file | afatguy | Shell Programming and Scripting | 4 | 09-14-2006 10:25 PM |
| replace a string in a file | ratan2204 | Shell Programming and Scripting | 7 | 05-10-2006 10:40 AM |
| replace string in binary file | sg1207 | Shell Programming and Scripting | 2 | 07-29-2004 12:26 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Replace string in a file w/ a variable value
I am trying to replace the default home page for several mac user accounts, I wrote a script that will hunt the files down and replace them with a pre-configured set. The problem I am having is that the download destination path for the browser is hard coded into a .plist (text config file) file along with the homepage. The issue is that if I replace this file with a pre-configured version the homepage is changed successfully but the download location is then wrong and the browser won't be able to download anything.
the download path originally is something like /Users/rob/Desktop the altered one is something like /Users/sample/Desktop Because the /Users/sample/Desktop doesn't match the user I am replacing files for, there is a problem. So I would like to set the location in the pre-configured file to something like /Users/[PATTERN//PATTERN]/Desktop and have the script open the text file, look for the pattern and replace it with the value of a variable called $USER_NAME which I already have holding the proper user name earlier in the script. How can I have the script look inside the .plist file, find the pattern and replace it with a variable value? Thanks, Rob |
|
||||
|
Found this on another forum in case anyone is interested, seems straight forward enough.
Quote:
|
|
||||
|
Ok so the following works...... almost Code:
cat sample.txt | sed -e 's/abc/xyz/' >> result.txt The only problem is, I want to use variables instead of abc and xyz so something like Code:
SEARCH="REPLACETHISTEXT" REPLACE="Hello" cat sample.txt | sed -e 's/$SEARCH/$REPLACE/' >> result.txt When I try this, nothing happens, are the variables not available due to the pipe? Is there a way around this? Thanks, Rob |
|
||||
|
Quote:
Thanks, Rob |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|