I am using below code to validate whether datatype,length and date format is correct as defined in file_layout.
Below code is able to find only one error in a row,if there is more than one error in a same row then code is not able to highlight second error.
How to customize the below code to find all errors in a particular row.
awk -F� '
NR==1{next}
{f="ok"}
$1!~/^[a-zA-Z0-9.%&@: -]{0,12}$/{f="ServicerID-error"}
$2!~/^[0-9]{0,10}$/{f="LetterHistoryID-error"}
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Loan_No-error"}
$4!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="PRIOR_LOAN-error"}
$5!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="InvLoanNo-error"}
$6!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="Letter_Date-error"}
$7!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Code-error"}
$8!~/^[a-zA-Z0-9.%&@: -]{0,50}$/{f="Letter_Type-error"}
$9!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="DataAsOfDate-error"}
{print f,$0}
' src_OCW_d_Letter_Tran_File_20130612_001.dat
pamu
June 18, 2013, 9:50am
2
srivalli:
I am using below code to validate whether datatype,length and date format is correct as defined in file_layout.
Below code is able to find only one error in a row,if there is more than one error in a same row then code is not able to highlight second error.
How to customize the below code to find all errors in a particular row.
CODE:
awk -F� '
NR==1{next}
{f="ok"}
$1!~/^[a-zA-Z0-9.%&@: -]{0,12}$/{f="ServicerID-error"}
$2!~/^[0-9]{0,10}$/{f="LetterHistoryID-error"}
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Loan_No-error"}
$4!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="PRIOR_LOAN-error"}
$5!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="InvLoanNo-error"}
$6!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="Letter_Date-error"}
$7!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Code-error"}
$8!~/^[a-zA-Z0-9.%&@: -]{0,50}$/{f="Letter_Type-error"}
$9!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="DataAsOfDate-error"}
{print f,$0}
' src_OCW_d_Letter_Tran_File_20130612_001.dat
Better way reset f
as {f=""}
.
and while assigning any string to f
use.
f=f?f" Error Code":"Error Code"
It will assign multiple error to the f
.
Regards,
pamu
Sorry i didnt get u,do i need to replace f as {f=" "} thats it?
awk -F� '
NR==1{next}
{f=" "}
$1!~/^[a-zA-Z0-9.%&@: -]{0,12}$/{f="ServicerID-error"}
$2!~/^[0-9]{0,10}$/{f="LetterHistoryID-error"}
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Loan_No-error"}
$4!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="PRIOR_LOAN-error"}
$5!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="InvLoanNo-error"}
$6!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="Letter_Date-error"}
$7!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Code-error"}
$8!~/^[a-zA-Z0-9.%&@: -]{0,50}$/{f="Letter_Type-error"}
$9!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="DataAsOfDate-error"}
{print f,$0}
' src_OCW_d_Letter_Tran_File_20130612_001.dat
---------- Post updated at 04:15 AM ---------- Previous update was at 03:57 AM ----------
Above code also finding only one error.
pamu
June 19, 2013, 6:44am
4
srivalli:
Sorry i didnt get u,do i need to replace f as {f=" "} thats it?
awk -F� '
NR==1{next}
{f=" "}
$1!~/^[a-zA-Z0-9.%&@: -]{0,12}$/{f="ServicerID-error"}
$2!~/^[0-9]{0,10}$/{f="LetterHistoryID-error"}
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Loan_No-error"}
$4!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="PRIOR_LOAN-error"}
$5!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="InvLoanNo-error"}
$6!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="Letter_Date-error"}
$7!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Code-error"}
$8!~/^[a-zA-Z0-9.%&@: -]{0,50}$/{f="Letter_Type-error"}
$9!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="DataAsOfDate-error"}
{print f,$0}
' src_OCW_d_Letter_Tran_File_20130612_001.dat
---------- Post updated at 04:15 AM ---------- Previous update was at 03:57 AM ----------
Above code also finding only one error.
You should assign error code to f and if f is already have assigned with error code then append second error code to first error code. for this purpose use below code.
f=f?f" Error Code":"Error Code"
Geting syntax errror if i replace f with f=f?f" Error Code":"Error Code",can you please change in below code where i should replace f with f=f?f" Error Code":"Error Code".
awk -F� '
NR==1{next}
{f="ok"}
$1!~/^[a-zA-Z0-9.%&@: -]{0,12}$/{f="ServicerID-error"}
$2!~/^[0-9]{0,10}$/{f="LetterHistoryID-error"}
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Loan_No-error"}
$4!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="PRIOR_LOAN-error"}
$5!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f="InvLoanNo-error"}
$6!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="Letter_Date-error"}
$7!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f="Code-error"}
$8!~/^[a-zA-Z0-9.%&@: -]{0,50}$/{f="Letter_Type-error"}
$9!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f="DataAsOfDate-error"}
{print f,$0}
' src_OCW_d_Letter_Tran_File_20130612_001.dat
pamu
June 20, 2013, 1:50am
6
awk -F� '
NR==1{next}
{f=""}
$1!~/^[a-zA-Z0-9.%&@: -]{0,12}$/{f=f?f" ServicerID-error":"ServicerID-error"}
$2!~/^[0-9]{0,10}$/{f=f?f" LetterHistoryID-error":"LetterHistoryID-error"}
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f=f?f" Loan_No-error":"Loan_No-error"}
$4!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f=f?f" PRIOR_LOAN-error":"PRIOR_LOAN-error"}
$5!~/^[a-zA-Z0-9.%&@: -]{0,15}$/{f=f?f" InvLoanNo-error":"InvLoanNo-error"}
$6!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f=f?f" Letter_Date-error":"Letter_Date-error"}
$7!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f=f?f" Code-error":"Code-error"}
$8!~/^[a-zA-Z0-9.%&@: -]{0,50}$/{f=f?f" Letter_Type-error":"Letter_Type-error"}
$9!~/^[0-9]{0,4}-[0-9]{0,2}-[0-9]{0,2} [0-9]{0,2}:[0-9]{0,2}:[0-9]{0,2}$|^[" "]{0,38}$/{f=f?f" DataAsOfDate-error":"DataAsOfDate-error"}
{print f,$0}
' src_OCW_d_Letter_Tran_File_20130612_001.dat
1 Like
Its working thanks for your help.
In below third column it should accept any special characters,numbers,alphabets etc.it should check only length of the column, data can be anything.
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f=f?f" Loan_No-error":"Loan_No-error"}
How to customize the code.
pamu
June 25, 2013, 4:24am
9
srivalli:
In below third column it should accept any special characters,numbers,alphabets etc.it should check only length of the column, data can be anything.
$3!~/^[a-zA-Z0-9.%&@: -]{0,10}$/{f=f?f" Loan_No-error":"Loan_No-error"}
How to customize the code.
We have default length
function in awk
, you can use this
length($3)==10{f=f?f" Loan_No-error":"Loan_No-error"}