Search multiple columns in each row

Hi All,

I have to search in multiple columns for multiple values, if the match is found then print the values as below.

Eg:

cat t1

Z|VLD_AB_P|VLD_CD_P|VLD_EF_F|VLD_GH_F|100
Y|VLD_AB_F|VLD_CD_F|VLD_EF_P|VLD_GH_P|101
if [ $2 == "VLD_AB_F" ] then print "Invalid AB in $6"
if [ $3 == "VLD_CD_F" ] then print "Invalid CD in $6"

---I want to print "Invalid AB, CD in $6"

--I started with this> a

wk -F"|" ' { if($2 == "VLD_AB_F") print $6; if($3 == "VLD_CD_F") print "Invalid BU";}' t1

Is there a way I can write a one-liner(in ksh) to search in each row/column for a value and if match is found then print the value

Can you show expected output?

if [ $2 == "VLD_AB_F" ] then print "Invalid AB in $6"
if [ $3 == "VLD_CD_F" ] then print "Invalid CD in $6"

---for the above I want to print "Invalid AB, CD in $6"
[for all the matches the corresponding value]

Basically, _F is failure. So I will check in few columns for this and echo the corresponding error message

nawk -F'|' '
{
   str=""
   for(i=1;i<=NF;i++) {
       n=split($i,a,"_")
       if(a[n]=="F") str=(str)?str","a[n-1]:a[n-1]
   } 
   if (str) print "Invalid " str " in $6"
}' myFile

First of all, I want to thank you all for your wonderful support here.

The requirement changed a little bit and I could not tweak the logic, can someone assist me here.

The requirement is:

Following is the input data

 
Z|VLD_AB_P|VLD_CD_P|VLD_EF_F|VLD_GH_F|100|UUU|0000-01-01
Y|VLD_AB_F|VLD_CD_F|VLD_EF_P|VLD_GH_P|101|ZZZ|2010-06-23

I have to check for

 
If [ `grep ^Z inpfile` ]
 then
       if [ `awk -F"|" '{print $2} line` -eq "VLD_AB_F" ]
          then
                 echo " Check failed in Z record, line number is .. ,keys are $6"
       fi
 
      if [ `awk -F"|" '{print $3} line` -eq "VLD_EF_F" ]
          then
                 echo " Check failed in Z record, line number is .??. ,keys are $5"
       fi
   ###similarly I have to check for all the fields and report the errors##
elif  [ `grep ^Y inpfile` ]
 then
       if [ `awk -F"|" '{print $2} line` -eq "VLD_AB_F" ]
          then
                 echo " Check failed in Y record, line number is ??.. ,keys are $6"
         fi
###similarly I have to check for all the fields and report the errors##

I thought of scanning each record and the field in the file by nested if. Wanted to know if we can achieve this thru awk single liners.

 
###similarly I have to check for all the fields and report the errors##

Based on What ???

Please post a sample case , which shows the input and the expected output.

Regards
Ravi

I apologize for the confusion. In Field 2,3,4,5 I will check for the following and If I find the match I will echo the message.

 
ErrCodes: VLD_AB_F|VLD_CD_F|VLD_EF_F|VLD_GH_F
 
Z|VLD_AB_P|VLD_CD_P|VLD_EF_F|VLD_GH_F|100|UUU|0000-01-01
Y|VLD_AB_F|VLD_CD_F|VLD_EF_P|VLD_GH_P|101|ZZZ|2010-06-23
 
If field -1 = Z && field2 (delim - 2) = VLD_AB_F Then print"Check failed in Z record, line number is .. ,keys are $6"
If field -1 = Z && field3 (delim - 3) = VLD_CD_F Then print"Check failed in Z record, line number is .. ,keys are $7"
If field -1 = Z && field4 = VLD_EF_F Then print"Check failed in Z record, line number is .. ,keys are $8"
If field -1 = Z && field5  = VLD_GH_F Then print"Check failed in Z record, line number is .. ,keys are $6"
 
###similarly for Y record
If field -1 = Y && field2 (delim - 2) = VLD_AB_F Then print"Check failed in Y record, line number is .. ,keys are $6"
###---so on for other fields in Y record
###--There will be multiple Z/Y records in the file and I have to scan all the records##