check the status and send an email with status

Hi,

We have a text file which has the following data.

ISA~00~ ~00~ ~ZZ~VISTN ~ZZ~U1CAD ~051227~183
7~U~00200~000011258~0~P~<
GS~FA~EE05J~U1CAD~051227~1831~000011258~X~002002
ST~997~0001
AK1~SH~247
AK2~856~2470001
AK5~A
AK2~856~2470002
AK5~A
AK9~A~2~2~2
SE~8~0001
GE~1~000011258
IEA~00001~000011258

ISA~00~ ~00~ ~ZZ~F159B ~ZZ~U1CAD ~051227~191
3~U~00200~000011467~0~P~<
GS~FA~AF52M~U1CAD~051227~1913~000011467~X~002002
ST~997~0001
AK1~SH~53
AK2~856~530001
AK5~A
AK9~A~1~1~1
SE~6~0001

The data I am looking for is in the first line that starts with ISA and the third column data is �~ZZ~F159B� and �~ZZ~VISTN�.

On the basis of the above mentioned segments, I have to assign them status either as pass or fail, which has been accomplished by the code snippet provided by Vgersh99 and Rancha.

grep "~ZZ~" <data file> | nawk '{ print ($3=="~ZZ~VISTN") ? "passed":"failed" }'

Now the new requirement is that I have to send an email, which should have the status in the body of the email. Can this be achieved in one script or I have to write two scripts like one has the static body of the email and it just expects two arguments.

Template for static email:

Please be advised that the EDI ASN has been �status� (either passed or failed).

Hope this is not too confusing.

Regards,
Inder

grep "~ZZ~" dat.txt | nawk '{ print ($3=="~ZZ~VISTN") ? "Please be advised that
the EDI ASN has been passed":"Please be advised that the EDI ASN has been failed
" }'

:slight_smile:

or in general

grep "~ZZ~" dat.txt| awk '{
if ( $3 == "~ZZ~VISTN" ) {
print "huge msg with status passed"
}
else
print "another message with status failed"
}'

Hi,

Thanks a lot!!!

It works like a treat!!

Is it possible to re-direct this message to some file or send an email?

Regards,
Inder

To email the message=

grep "~ZZ~" dat.txt| awk '{
if ( $3 == "~ZZ~VISTN" ) {
print "huge msg with status passed"
}
else
print "another message with status failed"
}' | mail urid@whatever.com

or
to redirect it to some file

grep "~ZZ~" dat.txt| awk '{
if ( $3 == "~ZZ~VISTN" ) {
print "huge msg with status passed"
}
else
print "another message with status failed"
}' > redirect_file_name