Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help reading a file in AIX 5.2

Status
Not open for further replies.

yaway

IS-IT--Management
Aug 7, 2003
12
US
I have a file with two lines for data and I need to search the file for only one word. If I find the work I need to run a script (Which I have already) if not I need the program to do nothing.

The word I am looking for is ONLINE.

Thank You
Yaway
 
Here's one way. I'm sure there are far better ones:

for ONLINE in `cat filename.txt`
do
<command>
done
 
oops. forget this. even if ONLINE isn't in there, the command runs.

Sorry.
 
Ok. I tested this one. Again, I am sure there are far better ways to do this.

#!/bin/ksh
cat filename.txt | while read line
do
if [[ $line = *'ONLINE' ]]
then
<command>
else
echo &quot;not there&quot;
fi
done

 
I get an error message saying

Syntax error line 6 'then' is not expected
 
Check your typing, including blank spaces. I copied what I typed here and pasted it into a file, ran it, and it worked.
 
Thank You
I found the problem it was a space. I have run the script but I am still having a problem. I think it is the data file.

The data file looks like this

(Blank Line)
This is currently the ONLINE side.
This is the B side.

When I read the file I just get ONLINE not found.

Thank You for all your help
 
yaway,

If I were you, I'd follow the advice you are getting in the thread just like this that you started in Unix scripting. They have you on the right track. Just watch your typing, including spacing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top