1833275 Members
2873 Online
110051 Solutions
New Discussion

Re: Variable parse

 
SOLVED
Go to solution
Leo The Cat
Regular Advisor

Variable parse

Hi

I have this incoming for a grep command.
AAA=1
BBB=1
CCC=2
DDD=533
EEE=991

Question: How to exploit the parse to call a function with the value after the '=' operator.
func(1)
func(1)
func(2)
func(553)
func(991)
...


Bests Regards
Den

4 REPLIES 4
James R. Ferguson
Acclaimed Contributor

Re: Variable parse

Hi Den:

Why not something like:

# awk -F= '{system("echo "$2)}' file

...where 'echo' is your function.

Regards!

...JRF...
Leo The Cat
Regular Advisor

Re: Variable parse

Hi James


It's because my function is in my ksh

function testentry {

echo "in"
echo $1
...
}

awk -FSERVICE= '{system("testentry "$2)}' /su02/automationlogs/009/odb_SrvLoop_RetrieveServiceNames.log

The run has errors like this:

Global TnsNames.ora check
Tue Dec 21 11:30:02 EST 2010

Check is running from stha2a034

__ stha24041 __
stha24041::HCMVNL2 ===== > INFO:: Undeterminated database version.
stha24041::HCMVNL2 ===== > INFO:: Database seems to be unreachable, bypassed.
stha24041::NIKDEV ===== > INFO:: Datebase is not define in /etc/oratab.
< End of check for stha24041
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.
sh: testentry: not found.

Bests Regards
Den

James R. Ferguson
Acclaimed Contributor
Solution

Re: Variable parse

Hi (again) Den:

> t's because my function is in my ksh

OK, consider something like this:

# cat ./myparse
!/bin/sh
MYINPUT=$@
function MYFUNC
{
echo "I see $@"
}
for VAR in ${MYINPUT}
do
VAL=$(echo ${VAR} | cut -d"=" -f2)
MYFUNC ${VAL}
done

...

You could do:

# ./myparse a=1 b=2 c=3

# ./myparse $(< inputfile)

# ./myparse $(grep "=" inputfile)

Regards!

...JRF...
Leo The Cat
Regular Advisor

Re: Variable parse

The Last post-solution makes the job. Thanks James!