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