Search a specific string

Hi,

I have following requirement. Pls suggest.
To search a string in a file which is combination of character and number(always 9 digit, but numeric). if found then caputure the exit return code as 0 else 1 , if 0 then next job can be triggerd. If exit code is 1, should return a failure notice.

character never changes. Number (9 digits) changes time to time.

e.g string "The maxinum number genrated : 123456789"

if [ "`grep "The maxinum number genrated :" $FILE `" ="" ] ; then
   exit 1
else 
  exit 0
fi

My requirement is to delete all file names which are having .CON extension from a particular directory.Please help with a script in how to do that?..Please help..

Thanks in advance..

Thanks for your reply but thats doesn't work for me. It displays nothing in the screen i hit ctl c to come out the script.

simply

grep -E "The maxinum number generated : [0-9]{9}$" $FILE 2>&1 >/dev/null && {
   # do next job
} || {
   exit 1
}

Hello daPeach Is that woking for you. I tried to execute your's script but i have no idea why this not executing for me.

Hi zooby,

did you rewrite it, changing the comment "# do next job" to the command you want to process?

using ksh/zsh/bash

echo "foo
foobarbaz : 123456789
bar" | grep -E "foobarbaz : [0-9]{9}$" 2>&1 >/dev/null && {
   echo OK
} || {
   echo KO
}

gives OK.

what shell do you use?

The above script executed successfully. and it returned Ok.

I use ksh and rewritten frist script as

grep -E "The maxinum number generated : [0-9]{9}$" $FILE 2>&1 >/dev/null && {echo " strat next job"} || { exit 1 }

even i used without E option also. but i can't get the output. Can you tell me what went wrong.

find /Particular_directory -name *.CON -exec echo rm {} \;

you need a space after openning curly brackets and a semi-colon and a space before closing curly brackets, like this

grep -E "The maxinum number generated : [0-9]{9}$" $FILE 2>&1 >/dev/null && { echo " strat next job"; } || { exit 1; }

Hi daPeach,

Thank you so much. When i tried before eventhough file exist in the path where i execute script it is not executed. The issue is with file path. i forced to read the file in specfic path. now it works!!!:slight_smile: Thanks again.