tags:

views:

37

answers:

3

hi

the following test syntax is part of ksh script

   [[ $PARAM = TRUE ]] &&  [[ ` echo $LINE_FROM_FILE | grep -c Validation ` -eq 1 ]] && print "find Validation word"

Can I get some other creative syntax/solution/command to verify if Validation word exists in LINE_FROM_FILE without to use the echo command?

LINE_FROM_FILE="123 Validation V125 tcp IP=1.2.56.4"

remark: need to match exactly Validation word

lidia

A: 

You could do it using case:

case $LINE_FROM_FILE in
    *Validation*)
        echo "found word Validation"
        ;;
    *)
        echo "did not find word Validation"
        ;;
esac
Miikka
I cant use case see my new edit [[ $PARAM = TRUE ]]
lidia
A: 

You can use Parameter expansion that removes everything up to and including Validation and compare that to the normal expansion of the parameter. If they are not equal the parameter contains Validation.

[[ "${LINE_FROM_FILE##* Validation }" != "${LINE_FROM_FILE}" ]]

(Since there are always spaces before and after Validation these can be included in the pattern. I do not know of an other way to match beginning and end of word in shell patterns)

Peter van der Heijden
lidia
try with LINE_FROM_FILE="1 2 3 ValidationWORD" , then you see that its also match -:(
lidia
Your `grep` version would match that line also. What I did was replicate what that version did.
Peter van der Heijden
yes but I want to match exactly the Validation word , I agree that grep not do the Job well
lidia
Are the spaces in front of Validation and after Validation always present?
Peter van der Heijden
yes I have always space before Validation and after Validation word
lidia
In that case the spaces can be included in the pattern. I have edited my post.
Peter van der Heijden
A: 
[[ $PARAM = TRUE ]] &&  [[ "$LINE_FROM_FILE" == *Validation* ]] && print "find Validation word"
Dennis Williamson

related questions