Operating System - HP-UX
1833729 Members
2471 Online
110063 Solutions
New Discussion

Reading a line from a file

 
dude70_1
Advisor

Reading a line from a file

Hi Guys,

I have a file where I have some properties. I want to read their value by property name like..

p1=value1
p2=value2

one time I want to read value of just p2. How do I do it?

Thanks in adv.

4 REPLIES 4
Michael Schulte zur Sur
Honored Contributor

Re: Reading a line from a file

Hi Dude70,

try this:

grep "^p2=" file

do you want to set the variable in the script or just see, what is it?

the value you get by:
string=`grep "^p2=" file`
value=`expr "${string}" : ".*=\(.*\)"`

greetings,

Michael


Michael Schulte zur Sur
Honored Contributor

Re: Reading a line from a file

Hi Dude70,

you have accidently opened two threads for the same problem. Maybe you should ask that the second thread be deleted.

greetings,

Michael
I.Delic
Super Advisor

Re: Reading a line from a file

Hi,

Perhaps you shuld make een array. Then you can read all of your variables.

Succes

Idriz
John Carr_2
Honored Contributor

Re: Reading a line from a file

cat filename | awk -d "=" '{ print $2}'

;-)
John.