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

how to replace a file and save it i

Reply to Message Icon

Original Message
Name: arun.s
Date: November 16, 2005 at 03:13:35 Pacific
Subject: how to replace a file and save it i
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


Report Offensive Message For Removal


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

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

it's ok.


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: how to replace a file and save it i

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge