Computing.Net > Forums > Unix > how to replace a file and save it i

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how to replace a file and save it i

Reply to Message Icon

Name: arun.s
Date: November 16, 2005 at 03:13:35 Pacific
OS: unix
CPU/Ram: 255
Comment:


Hi guys

this my sample file sample.ksh

DBUID=testdatabase
DBLOC=wm4r2

i want replace DBUID=testdatabase by DBUID=$myvariable (i.e myvariable=arundatabase). the name testdabase is not fixed and it changes from time to time. so my search criteria is DBUID. after replacing the line i need to save it in same file

thus finally i want my sample.ksh file as

DBUID=arundatabase
DBLOC=wms4r2

this is how i want u to help u.. read the line from a file and replace it from mychoice data and save it back to the same file without altering the other contents.

i m looking forward to your help.. get me the solution as soon as possible

thanks
Arun



Sponsored Link
Ads by Google

Response Number 1
Name: koala95
Date: November 16, 2005 at 04:31:19 Pacific
Reply:

#/bin/ksh
myvariable=arundatabase
sed "s/DBUID=.*/DBUID=$myvariable/" sample.ksh >/tmp/sample.ksh
mv /tmp/sample.ksh .

it's ok.


0
Reply to Message Icon

Related Posts

See More


Unix replacing text output of a cmd>replace a...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: how to replace a file and save it i

how to replace a file in a .zip fil www.computing.net/answers/unix/how-to-replace-a-file-in-a-zip-fil/7497.html

How to copy a file in Telnet www.computing.net/answers/unix/how-to-copy-a-file-in-telnet/5921.html

How to parse a file of 199 col? www.computing.net/answers/unix/how-to-parse-a-file-of-199-col/7250.html