Computing.Net > Forums > Unix > Replacing values in a file

Replacing values in a file

Reply to Message Icon

Original Message
Name: amit4g
Date: February 1, 2007 at 00:20:04 Pacific
Subject: Replacing values in a file
OS: hp-ux(11.23)
CPU/Ram: PA
Model/Manufacturer: PA
Comment:

Hi,

how do we change a variable's value in a file?
e.g.
$ cat <file1>
AGE=1
bla bla...........

i need to change the value of variable "AGE" to a newvalue(let's say "0")

Thanks,
Amit


Report Offensive Message For Removal


Response Number 1
Name: nails
Date: February 1, 2007 at 19:35:46 Pacific
Reply: (edit)

Hi:

We've been talking about gres:

http://www.computing.net/unix/wwwbo...

# gres
pattern=$1
replacement=$2

A="`echo | tr '\012' '\001' `"
sed -e "s$A$pattern$A$replacement$A" $3
# end script

Here is an example

gres "Age=0" "Age=1" filename


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: Replacing values in a file

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 6 Days.
Discuss in The Lounge