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

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



 
Why not just use grep, or am I missing something significant.

Something along the lines of....

#!/bin/bash
grep ONLINE myfile_name > /dev/null 2> /dev/null
if [[ $? == 0 ]]
then
echo "ONLINE FOUND - RUNNING SCRIPT"
/dir/dir/script_to_be_run
exit 0
fi
echo "ONLINE NOT FOUND - NO ACTION TAKEN"
exit 1
 
Nothing happens when I run this script. I must be doing something wrong. I do not even get the echo to work.
 
I'm no bash scripter, but translating it to regular bourne shell would be something like:

Code:
#!/bin/sh
CHECK=`grep ONLINE myfile_name`
if [ -n "$CHECK" ]
then
    #do stuff
fi


--
Andy
 
When I run the script I get an error 'then' is not expected.
 
I found the problem with the then statement. When I run the script I get errors that it can not find ONLINE. The input file looks like this


blank line
This is currently the ONLINE side.
This is the B side.

Any help would be great.
Thank You
 
Also try.....

grep -q ONLINE myfile && echo found || echo not found
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top