![]() |
|
|
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 |
| replace character in a string pattern and save the change in same file | mihir0011 | Shell Programming and Scripting | 2 | 09-26-2007 06:31 PM |
| 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 in a file | ratan2204 | Shell Programming and Scripting | 7 | 05-10-2006 10:40 AM |
| Replace all occurances of a string in all file-/foldernames, recursively | TheMJ | Shell Programming and Scripting | 2 | 04-12-2006 02: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 a string with content from another file
Hi,
I'm a newbi in shell script. Here what I want to do: FileA: bor bor bor xxxx bib bib bi FileB: something something something I want to replace string "xxxx" in FileA with contents of FileB. i tried with sed: fileb=`cat FileB` reg=xxxx file=FileA sed -e "s+$reg+$fileb+g" $file but it said: sed: Function s+reg+ cannot be parsed. thanks, |
|
||||
|
while a shell solution is on the way , here is an alternative, in Python Code:
>>> import fileinput
>>> Bcontents = open("fileB").read() #fileB contents stored as string
>>> for lines in fileinput.FileInput("fileA",inplace=1): #inplace editing of fileA
... lines = lines.strip() #get rid of newlines
... if lines.startswith("xxxx"):
... lines = Bcontents
... print lines
In fileA: bor bor bor something something something bib bib bi Last edited by ghostdog74; 09-14-2006 at 02:03 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|