Reading a file line by line but...

I need to read a file line by line, but I am only interest in lines with a specific format.
I have a file that looks like the folowing, but I want to start where my database names start.

I want to start with the "mydb" line. None of my databases have the letters db in the name. This file can change in size since we check it and it gets a revision tagged at the top.

 
while read LINE
do
  DBNAME=`echo $LINE | cut -d ":" -f1`
done < $ORATAB

# Revision 1.1 2005-09-17 13:25:06-04 oracle
# Initial revision
#
#

# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
*:/opt/oracle/product/10120/mrca:N
*:/opt/oracle/product/10.1.0.3:N
*:/opt/oracle/product/10.1.0.3-devo:N
*:/opt/oracle/product/10.1.0.3_test:N
*:/opt/oracle/product/9206/dev/internal:N
*:/opt/oracle/product/9206/dev/id:N
*:/opt/oracle/product/9206/test/infrast:N
*:/opt/oracle/product/9206/test/id:N
*:/opt/oracle/product/9206/uat/id:N
mydb:/opt/oracle/product/10.2.0.4:N

Something like this may help you:

dbName="mydb"

lineNo=`egrep -n '^'"${dbName}"'' ${ORATAB} | cut -f' -d":"`

if [ ${#lineNo} -eq 0 ]
then
	echo "ERROR: Database not present: [${dbName}]"
	exit 1
fi

tail -${lineNo} ${ORATAB} | \
while read oraTabLine
do
	<Do Something with the line>
done

shouldn't it be

tail +${lineNo} ${ORATAB} | \

instead of

tail -${lineNo} ${ORATAB} | \

?

tail -<n> would take the <n> last lines of the file, whether tail +<n> would take from the <n>th line (from top) , until the end of the file

If you want from top, use head -<n>

Regards.

By using sed

To read 22nd line the file,

sed -n '22p' <file name>

there are many database names. So there could be 10 lines with databases. The databases can have any names.

mydb
hisdb
thatdb
hello
goodbye

I think what I want to is grep for

:/opt/oracle/product/9206/test/infrast:N

then pipe it into another grep another grep that looks for lines that do no have a *

grep -i :/mypath/myfile | grep -i "*"

so grep -i will find lines that have a *, how do I find lines that will not?
How do I loop on the output one line at a time, without redirecting it to a file?

look at "-v" option of grep

while IFS=: read -r db junk; do
    case $db in
        [\#*]*) continue;;
            ?*) echo "DBNAME: $db";;
    esac
done < "$ORATAB"