Computing.Net > Forums > Unix > Search a string and generate a error message.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search a string and generate a error message.

Reply to Message Icon

Name: ch Bushu
Date: May 13, 2009 at 22:51:59 Pacific
OS: Unix
Subcategory: General
Comment:

Hi Frens,

I have to search for a string and need to display a error message if that sting is not found in the file....

I can use the command:

> grep "String" filename

for searching the string but, in addition to that I have to add - if that string not found echo "Sting not found "


Can anyone help me for this?

Thanks in advance...



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: May 14, 2009 at 02:06:01 Pacific
Reply:

check for $?.


0

Response Number 2
Name: lankrypt0
Date: May 14, 2009 at 07:53:43 Pacific
Reply:

a simple if works:
#!/usr/bin/ksh

isfound=$(grep word file)

if [[ $isfound = "" ]];then
echo not found
else
echo $isfound
fi


0

Response Number 3
Name: ch Bushu
Date: May 14, 2009 at 20:37:15 Pacific
Reply:

Thanks a lot..My problem is solved.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Search a string and generate a error message.

korn script novice www.computing.net/answers/unix/korn-script-novice/4773.html

recursive search of subdirectories www.computing.net/answers/unix/recursive-search-of-subdirectories/6250.html

Unix Shell Script Help www.computing.net/answers/unix/unix-shell-script-help/7753.html