Shell scripting ??

I have a file in /etc/ called oratab

how do i read the file
# *:/apps/oracle/product/8.1.6ctmdev01:N
# *:/apps/oracle/product/8.1.6ctmdev01:N
QBIP:/apps/oracle/product/8.1.6qbip01:Y
QBID:/apps/oracle/product/8.1.6qbid01:Y
QBIT:/apps/oracle/product/8.1.6qbit01:Y

and read
QBIP
QBID
QBIT
into Oracle_value variable and pass that variable into my shell script?? the purpose is to run that 1 script on 3 instances??

try this...

Oracle_value=`cut -d : -f 1 /etc/oratab | grep '[A-Z]+' | sed 's/\n/ /'`

this will put "QBIP QBID QBIT " in Oracle_value

:slight_smile:
Vishnu.

Vishnu
thanks for the info

the problem is to avoid # or * and how do i read thru the file??

# *:/apps/oracle/product/8.1.6ctmdev01:N
# *:/apps/oracle/product/8.1.6ctmdev01:N
QBIP:/apps/oracle/product/8.1.6qbip01:Y
QBID:/apps/oracle/product/8.1.6qbid01:Y
QBIT:/apps/oracle/product/8.1.6qbit01:Y

Jigar

How about something like this:

#! /usr/bin/ksh

IFS=:
exec < /etc/oratab
while read Oracle_value junk ; do
        firstchar=${Oracle_value%${Oracle_value#?}}
        [ $firstchar = '#' ] && continue
        echo  Oracle_value =  $Oracle_value
done
exit 0

Oracle_value=`cut -d : -f 1 /etc/oratab | grep '[A-Z]+' | sed 's/\n/ /'`

in this cut will isolate the first column in all lines using : as separator and [A-Z]+ in grep ensures that you dont read the columns having # etc and sed replace newlines with spaces.

If you want a loop in which you can pass the content of whole lines having QBIP etc. You may try this..

while i in `grep '^[A-Z]+:.*$' /etc/oratab`
do
echo $i
done

this will echo only those lines beginning with all caps and ending with a : . So effectively isolating those lines containing QBIP etc.

sorry..

replace "while i in" in my above reply with "for i in"...

thank you!
Vishnu.

How about this

awk -F":" '/^[A-Z]/ { print $1}'

/<reg exp>/ will remove unwanted lines.:wink: