![]() |
|
|
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 |
| Searching patterns in 1 file and deleting all lines with those patterns in 2nd file | toms | Shell Programming and Scripting | 4 | 08-14-2009 07:53 AM |
| To find 3 patterns in a file | ali560045 | Shell Programming and Scripting | 2 | 06-05-2009 06:48 AM |
| looking for patterns/tex in a .doc file | Straitsfan | UNIX for Dummies Questions & Answers | 4 | 05-15-2009 12:05 PM |
| grep patterns - File | dhanamurthy | Shell Programming and Scripting | 1 | 05-08-2008 11:24 PM |
| How to cut multiple patterns from a file? | Vijay06 | Shell Programming and Scripting | 5 | 11-26-2007 09:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
||||
|
Hi Everybody,
Can we replace the contents of a file without using a temporary file. For ex: I need to relpace the value "old" with "new", I can do it using the sed replace pattern, but I do not want to use a temporary file. Also, from the questions posted in the past I could see a fantastic command to do this printf '1,$ s/old/new/g\nw! samp.txt\nq!'| ex - samp.txt But, with the same command I am not able to replace the value of a variable For ex: var1='new' printf '1,$ s/new/$var1/g\nw! samp.txt\nq!'| ex - samp.txt The above command doesn't replace the value of the variable. |
|
||||
|
You can use sed to replace stings without using a temp file using its -i (edit in place) flag. Shell variables are not interpreted inside single quotes. You should use double quotes or terminate the single quote before $var and start it after $var. Code:
$ printf '1,$ s/new/'$var1'/g\nw! samp.txt\nq!'| ex - samp.txt |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|