printing a line of a file

I am trying to write a script that when triggered by an ip address it will run the following
export DAVIDCOUNT=`(fgrep -ce 140.147.146.146 /export/home/ipconnect.txt) >> /local/cron/test_listen_out`;
I think this is my problem line.
What I like this line to do is when it sees the 140.147.146.146 ip address, it goes to the ipconnect.txt file, finds the line that corresponds to the ip address and print the whole line of text that has 140.147.146.146.
Is this possible?

You really need to split this line into two commands. It looks like you are trying to get a count with the '-c' option, as well as outputting a line of text. Try:

COUNT=`grep -c 140.147.146.146 ipconnect.txt`
grep 140.147.146.146 >> test_out

I think that the former thread is not correct.
What I am trying to do is when the script is triggered by
an ip address, it goes to a file called ipconnect.txt and
print the row that has the corresponding ip address in it.
The data in ipconnect is a list of ip address followed by a
tab and then the owner's ip address.
This is the entire script and I think that the netstat is
what need to be looked at.

export HOUR=`/usr/bin/date +%H`
export MINUTE=`/usr/bin/date +%M`
export REMOTECOUNT=`ps -ef | grep LOCAL=NO | wc -l`;
if [ $REMOTECOUNT -ne 1 ]
then
export REMOTER=`expr ${REMOTECOUNT} - 1`
print $REMOTER "=REMOTE CONNECTIONS" > /cron/test_listen_out;
netstat -an | grep "50.1521" | cut -c22-42 | egrep -v /cron/stars >> /cron/test_listen_out;
export DAVIDCOUNT=`fgrep -ce 140.147.146.146 /ipconnect.txt`;
fgrep 140.147.146.146 >> /cron/test_listen_out;
if [ $DAVIDCOUNT -ne 0 ]
then
print "David Williamson" >> /cron/test_listen_out;
fi
...
fi

Yes, you are right. You run the netstat command and match the output to the IP address you are trying to match in a condition statement. When it matches, you can either pass the matching IP address to another executable script to read the .txt file and do what you want, or read the .txt file from the first script and match.

I would do it all in one script, if not too complex, and execute the script from the crontab file every couple of minutes. You will need a flag and a timer to insure that you do not get multiple hits on an IP address, because the address will linger in netstat longer than the interval between crontab executions.

I would write this in PERL, because PERL is better suited for this that SH, KSH, and these type shells.

Thanks. You are really good.
When the ip detected matches the ip of ipconnect.txt, I like to have the corresponding row of ipconnect.txt
to be printed. I do not know how to do this. How can this be done.
I do not know Perl. Could it be done in KSH?

Yes, you can do it in any scripting language. Use the one which is the most comfortable for you. KSH will work as well all shell scripting languages. I recommended PERL because of its superior file I/O and pattern matching functions. However, if you don't know PERL, it is certainly possible with KSH.

Feel free to post your final script. It should not be too long, based on your posts. Happy to review.

Ok, here it is again.

export HOUR=`/usr/bin/date +%H`
export MINUTE=`/usr/bin/date +%M`
export REMOTECOUNT=`ps -ef | grep LOCAL=NO | wc -l`;
if [ $REMOTECOUNT -ne 1 ]
then
export REMOTER=`expr ${REMOTECOUNT} - 1`
print $REMOTER "=REMOTE CONNECTIONS" > /cron/test_listen_out;
netstat -an | grep "50.1521" | cut -c22-42 | egrep -v /cron/stars >> /cron/test_listen_out;
export DAVIDCOUNT=`fgrep -ce 140.147.146.146 /ipconnect.txt`;
fgrep 140.147.146.146 >> /cron/test_listen_out;
if [ $DAVIDCOUNT -ne 0 ]
then
print "David Williamson" >> /cron/test_listen_out;
fi
...
fi

The ... are more namecounts which is too repetative to type.
So DAVIDCOUNT is a sample of all of the other counts that follows.