Based on your requirements, the solution for step (2) can be very complex as you did not specify how many different
error codes exists, thus I just display the error and you can use another tool to count the different ones.
Here is what I came up with:
#!/usr/bin/ksh
typeset -i mCnt1=0
mLOrig='originNodeType : "IVR"'
mLVouch="voucher : '0'D"
mLProf='rProfileID : "ZZZZ"'
mLONType='originNodeType : "IVR"'
mLErr="errorCode :"
while read mLine; do
mP1to4=$(echo ${mLine} | cut -c1-4)
if [[ "${mP1to4}" = "TYPE" ]]; then
if [[ "${mLine}" = "TYPE1" ]]; then
if [[ "${mOrig}" = "Y" && "${mVouch}" = "Y" && "${mProf}" = "Y" ]]; then
mCnt1=${mCnt1}+1
fi
mType="1"
mOrig="N"
mVouch="N"
mProf="N"
else
if [[ "${mLine}" = "TYPE2" ]]; then
mType="2"
mONType='N'
else
mType="?"
fi
fi
fi
if [[ "${mType}" = "1" ]]; then
if [[ "${mLine}" = "${mLOrig}" ]]; then
mOrig='Y'
else
if [[ "${mLine}" = "${mLVouch}" ]]; then
mVouch='Y'
else
if [[ "${mLine}" = "${mLProf}" ]]; then
mProf='Y'
fi
fi
fi
fi
if [[ "${mType}" = "2" ]]; then
if [[ "${mLine}" = "${mLONType}" ]]; then
mONType='Y'
else
if [[ "${mONType}" = "Y" ]]; then
mP1to11=$(echo ${mLine} | cut -c1-11)
if [[ "${mP1to11}" = "errorCode :" ]]; then
echo "TYPE2 IVR ${mLine}"
fi
fi
fi
fi
done < input_file
echo "Found ${mCnt1} condition in TYPE1"
Is there someway to keep the pattern search mLOrig='originNodeType : "IVR"' to be space insensitive. Like we get match in this case and even if we have 'originNodeType : "IVR"' (multiple blank or tabs)?
Hi birei,
Yes in the sample file the output which you mentioned is ok. I need count.
In sample pattern below, count for TYPE2 record with sample pattern should be 2.
This code will work on mixed cases and multiple spaces:
#!/usr/bin/ksh
typeset -i mCnt1=0
mLOrig='originnodetype:"ivr"'
mLVouch="voucher:'0'd"
mLProf='rprofileid:"zzzz"'
mLONType='originnodetype:"ivr"'
mLErr="errorcode:"
tr -A '[:upper:]' '[:lower:]' < input_file | tr -d ' ' |
while read mLine; do
mP1to4=$(echo ${mLine} | cut -c1-4)
if [[ "${mP1to4}" = "type" ]]; then
if [[ "${mLine}" = "type1" ]]; then
if [[ "${mOrig}" = "Y" && "${mVouch}" = "Y" && "${mProf}" = "Y" ]]; then
mCnt1=${mCnt1}+1
fi
mType="1"
mOrig="N"
mVouch="N"
mProf="N"
else
if [[ "${mLine}" = "type2" ]]; then
mType="2"
mONType='N'
else
mType="?"
fi
fi
fi
if [[ "${mType}" = "1" ]]; then
if [[ "${mLine}" = "${mLOrig}" ]]; then
mOrig='Y'
else
if [[ "${mLine}" = "${mLVouch}" ]]; then
mVouch='Y'
else
if [[ "${mLine}" = "${mLProf}" ]]; then
mProf='Y'
fi
fi
fi
continue
fi
if [[ "${mType}" = "2" ]]; then
if [[ "${mLine}" = "${mLONType}" ]]; then
mONType='Y'
else
if [[ "${mONType}" = "Y" ]]; then
mP1to10=$(echo ${mLine} | cut -c1-10)
if [[ "${mP1to10}" = "${mLErr}" ]]; then
echo "TYPE2 IVR ${mLine}"
fi
fi
fi
fi
done
echo "Found ${mCnt1} condition in TYPE1"