![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| overwrite specific lines in a file | csecnarf | Shell Programming and Scripting | 7 | 05-13-2008 08:01 AM |
| how to remove specific lines from a file | bluemoon1 | Shell Programming and Scripting | 17 | 10-07-2007 07:40 PM |
| replacing first line or lines in a file | Terrible | UNIX for Advanced & Expert Users | 3 | 06-28-2006 05:23 PM |
| Update specific lines in a file | aukequist | Shell Programming and Scripting | 3 | 11-15-2005 10:52 AM |
| How do you specific lines in a file? | hedgehog001 | UNIX for Dummies Questions & Answers | 2 | 08-22-2005 09:04 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
replacing specific lines in a file
Hi there
I have a file which has the lines Code:
# Serial number for hostid EXP_SERIAL_="" Code:
# Serial number for hostid $var1 EXP_SERIAL_$var1="$var2" cheers |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
........................................
Last edited by gauravgoel; 09-29-2006 at 04:58 AM. Reason: wrong solution |
|
#3
|
|||
|
|||
|
use this
Quote:
Last edited by gauravgoel; 09-29-2006 at 05:10 AM. |
|
#4
|
|||
|
|||
|
thats great but if i run that command from the command line it outputs the correct result to the screen but doesnt actually edit the file
How do i get it to make a permanent change to the file ?? |
|
#5
|
|||
|
|||
|
Code:
sed "s/old text/new text/g" input.txt > temp mv temp input.txt Code:
perl -pi -e "s/old text/new text/g" input.txt |
|
#6
|
|||
|
|||
|
that works great thankyou ....I wanted to avoid creating a new file and mv'ing it back over again....but if i have to do that then so be it
thanks for your help |
|
#7
|
|||
|
|||
|
You might try something like this if you don't want to create a file:
Code:
echo '%s/oldtext/newtext/g\nwq' | ex file |
|||
| Google The UNIX and Linux Forums |