korn shell (ksh) awk question

korn shell (ksh) awk question

Post by Susan Nova » Sat, 01 Jun 2002 08:57:49



I have an awk question that I hope someone can help me with.

In a korn shell script I am going through a file that has all the oracle
databases defined in it.  As part of the data in the line ($LINE), there is
the
oracle version which I want have contained in an environment variable
($ORACLE_VERSION).  When I run my script the only value that gets set is 901
even when the line has 817 and not the pattern 901.  Can someone tell me how
to
change the below lines such that it will work within a korn script on AIX
or
give me an alternative solution?

Thanks in advance.

#if the pattern is matched then the variable gets set
 ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/817/) print "817"}' `
 ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/901/) print "901"}' `
 export ORACLE_VERSION

 
 
 

korn shell (ksh) awk question

Post by Nick Hayne » Sat, 01 Jun 2002 21:59:08



> I have an awk question that I hope someone can help me with.

> In a korn shell script I am going through a file that has all the oracle
> databases defined in it.  As part of the data in the line ($LINE), there is
> the
> oracle version which I want have contained in an environment variable
> ($ORACLE_VERSION).  When I run my script the only value that gets set is 901
> even when the line has 817 and not the pattern 901.  Can someone tell me how
> to
> change the below lines such that it will work within a korn script on AIX
> or
> give me an alternative solution?

> Thanks in advance.

> #if the pattern is matched then the variable gets set
>  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/817/) print "817"}' `
>  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/901/) print "901"}' `
>  export ORACLE_VERSION

My idea:

There is nothing wrong with this code, so I am wondering how LINE gets
it's value.  Perhaps you are looking in the wrong place for the problem?
But I'd suggest one single awk script, or a case statement in shell, or
even the cut command.  But then I don't know your data or what you're
trying to do.

 
 
 

korn shell (ksh) awk question

Post by Kevin Bran » Sun, 02 Jun 2002 02:39:57


Maybe this will help:

cat /etc/oratab | cut -d: -f1,2 | awk '
BEGIN { FS="/" }
{
split($1,a,":")
printf("Instance: %s    Version: %s\n", a[1], $(NF) )

Quote:}'

This produces results like this:
Instance: o817    Version: 8.1.7
Instance: test1    Version: 8.1.7
Instance: test9     Version: 9.0.1

Hth

-Kevin


Quote:> I have an awk question that I hope someone can help me with.

> In a korn shell script I am going through a file that has all the oracle
> databases defined in it.  As part of the data in the line ($LINE), there
is
> the
> oracle version which I want have contained in an environment variable
> ($ORACLE_VERSION).  When I run my script the only value that gets set is
901
> even when the line has 817 and not the pattern 901.  Can someone tell me
how
> to
> change the below lines such that it will work within a korn script on AIX
> or
> give me an alternative solution?

> Thanks in advance.

> #if the pattern is matched then the variable gets set
>  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/817/) print "817"}' `
>  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/901/) print "901"}' `
>  export ORACLE_VERSION

 
 
 

korn shell (ksh) awk question

Post by Ralf Lammer » Sun, 02 Jun 2002 04:26:45


Susan Novak schrieb:

Quote:> I have an awk question that I hope someone can help me with.

> In a korn shell script I am going through a file that has all the oracle
> databases defined in it.  As part of the data in the line ($LINE), there is
> the
> oracle version which I want have contained in an environment variable
> ($ORACLE_VERSION).  When I run my script the only value that gets set is 901
> even when the line has 817 and not the pattern 901.  Can someone tell me how
> to
> change the below lines such that it will work within a korn script on AIX
> or
> give me an alternative solution?

> Thanks in advance.

> #if the pattern is matched then the variable gets set
>  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/817/) print "817"}' `
>  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/901/) print "901"}' `
>  export ORACLE_VERSION

Hi Susan!

Can you give an example of what $LINE looks like? Is it possible that "817" and
"901" will be matched in the same line? Your few lines can be coded as follows:

#!/bin/ksh
...
[[ $LINE = *817* ]] && ORACLE_VERSION="817"
[[ $LINE = *901* ]] && ORACLE_VERSION="901"
export ORACLE_VERSION

Or if $LINE may only contain one version you should better write

#!/bin/ksh
...
case "$LINE" in
*817*)    ORACLE_VERSION="817" ;;
*901*)    ORACLE_VERSION="901" ;;
esac
export ORACLE_VERSION

Bye,
Ralf

 
 
 

korn shell (ksh) awk question

Post by Lev Davidowitsch Bronstei » Mon, 03 Jun 2002 00:30:09


Ralf Lammers declarait :

Quote:> Susan Novak schrieb:
> > I have an awk question that I hope someone can help me with.

> > In a korn shell script I am going through a file that has all the oracle
> > databases defined in it.  As part of the data in the line ($LINE), there is
> > the
> > oracle version which I want have contained in an environment variable
> > ($ORACLE_VERSION).  When I run my script the only value that gets set is 901
> > even when the line has 817 and not the pattern 901.  Can someone tell me how
> > to
> > change the below lines such that it will work within a korn script on AIX
> > or
> > give me an alternative solution?

> > Thanks in advance.

> > #if the pattern is matched then the variable gets set
> >  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/817/) print "817"}' `
> >  ORACLE_VERSION=`echo $LINE | awk '{if ($0 ~/901/) print "901"}' `
> >  export ORACLE_VERSION
> Hi Susan!
> Can you give an example of what $LINE looks like? Is it possible that "817" and
> "901" will be matched in the same line? Your few lines can be coded as follows:
> #!/bin/ksh
> ...
> [[ $LINE = *817* ]] && ORACLE_VERSION="817"
> [[ $LINE = *901* ]] && ORACLE_VERSION="901"
> export ORACLE_VERSION
> Or if $LINE may only contain one version you should better write
> #!/bin/ksh
> ...
> case "$LINE" in
> *817*)    ORACLE_VERSION="817" ;;
> *901*)    ORACLE_VERSION="901" ;;
> esac
> export ORACLE_VERSION
> Bye,
> Ralf

Presumably Sarah is trying to read /etc/oratab, in which all the
Oracle instances are listed. It has the following format (oracle
installs per default in directories giving the version):

# sample /etc/oratab
# instance_: basedir_____________:start instance at system boot Y/N
ORACLE_SID1:/oracle/product/8.1.6:Y
ORACLE_SID2:/oracle/product/8.1.7:N
# eof /etc/oratab

If this is the case, Sarah, the following will work:

ORACLE_VERSION="$( grep -v '^#' /etc/oratab | grep MyINSTANCENAME |\
                   cut -f2 -d':' | sed 's/.*\///; s/\.//g' \
                 )"

Do yourself a favour, Sarah, and avoid awk for purposes like this:
way too big, way to slow and way to complex for things god has
created sed for. ;-)

Wolf
--
Article post via l'accs Usenet  http://www.mes-news.com
Accs par Nnrp ou Web

 
 
 

1. Question about Korn Shell (ksh)

In the Korn shell, I can hit the Esc key and bring back up my previous
commands (I'm a bad typer).
If I hit escape, then I can use the K or J key to move back or forward
to previous commands.

I would like to make it more like the Bourne-Again shell (bash) where
I can just hit the up or down arrow key to bring up previous
commands......is it possible to make the up and down arrow keys show me
my previous commands in ksh?  I 've looked all over for this info and
haven't found it.

Thanks
Sam Alexander

salex at nortel dot ca

2. Speed of DOS apps under Solaris x86

3. best korn shell resources and is there a korn shell faq

4. make PROBLEMS: make: *** No targets specified and no makefile found. Stop

5. Help w/awk, korn shell & writing to a file

6. what does: (2)No such file or directory: select claimed we could write, but in fact we couldn't. This is a bug in Windows mean?

7. Passing Values Between Korn Shell and Awk

8. Where to find UNIX Help

9. ISO-8859 in ksh / Korn Shell ?

10. ksh scripts in the Korn Shell book.

11. Solution to decoding QUERY_STRING in ksh (Korn Shell)

12. Korn Shell (ksh)