Operating System - HP-UX
1748128 Members
3900 Online
108758 Solutions
New Discussion юеВ

How to read the result of this command into a VARIABLE

 
SOLVED
Go to solution
Ramakrishna_4
New Member

How to read the result of this command into a VARIABLE

cat config.ini |grep FILE_SIZE|awk -F= '{print("")$2}'

Here I am reading a CONFIG.ini file and getting the value of a key-value pair.

I am able to get the result, but am not able to store this into a variable.

I tried many ways, but was unsuccessful.
Please help

Thanks
Ram
3 REPLIES 3
Mic V.
Esteemed Contributor
Solution

Re: How to read the result of this command into a VARIABLE

There are multiple ways and it partly depends on your shell.

For sh, one way is:

ANSWER=`cat config.ini |grep FILE_SIZE|awk -F= '{print("")$2}'`

or as a simpler example:

ANSWER=`/bin/ls`

Review the EXPORT statement in the shell.


For C shell, one way is:

set answer=`cat config.ini |grep FILE_SIZE|awk -F= '{print("")$2}'`

or as a simpler example:

set answer=`/bin/ls`

Review the difference between variables and environment variables.

There's lots more to this, but that will hopefully be a start. You might like Perl better if you're going to do a lot with strings.

HTH,
Mic

What kind of a name is 'Wolverine'?
Indira Aramandla
Honored Contributor

Re: How to read the result of this command into a VARIABLE

Hi Ram,

You can assign the outcome of the cat config.ini |grep FILE_SIZE|awk -F= '{print("")$2}' to a variable.

Let the variable be varout.
varout=`cat config.ini |grep FILE_SIZE|awk -F= '{print("")$2}'`

Note: the symbles before cat and the at the end after the single quotes are the acent symbol.


IA
Never give up, Keep Trying
Ramakrishna_4
New Member

Re: How to read the result of this command into a VARIABLE

Thanks a lot mic
ANSWER=`cat config.ini |grep FILE_SIZE|awk -F= '{print("")$2}'` is working perfectly ..

I wonder how i have missed it.
May be i have given an extra space somwhere.

Thanks a lot for the reply
Ram