Finding only one error in a row


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding only one error in a row
# 1  
Old 06-18-2013
Finding only one error in a row

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


Last edited by Scott; 07-01-2013 at 07:36 AM.. Reason: Removed formatting; fixed code tags
# 2  
Old 06-18-2013
Quote:
Originally Posted by srivalli
Code:
 
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.
Code:
f=f?f" Error Code":"Error Code"

It will assign multiple error to the f.

Regards,

pamu
# 3  
Old 06-19-2013
Code:
 
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 ----------

Code:
 
Above code also finding only one error.

# 4  
Old 06-19-2013
Quote:
Originally Posted by srivalli
Code:
 
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 ----------

Code:
 
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.
Code:
f=f?f" Error Code":"Error Code"

# 5  
Old 06-19-2013
getting syntax error

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".
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


Last edited by Scott; 07-01-2013 at 07:34 AM.. Reason: Fixed code tags
# 6  
Old 06-20-2013
Code:
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

This User Gave Thanks to pamu For This Post:
# 7  
Old 06-20-2013
Its working thanks for your help.

Last edited by Scott; 07-01-2013 at 07:35 AM.. Reason: Removed pointless code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

This is a question that is related to one I had last August when I was trying to sort/merge two files by millsecond time column (in this case column 6). The script (below) that helped me last august by RudiC solved the puzzle of sorting/merging two files by time, except it gets lost when the... (0 Replies)
Discussion started by: aachave1
0 Replies

2. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

3. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

My original files are like this below and I distinguish them from the AP_ID (file1 has 572 and file2 has 544). Also, the header on file1 has “G_” pre-pended. NOTE: these are only snippets of very large files and much of the data is not present here. Original File 1: ... (36 Replies)
Discussion started by: aachave1
36 Replies

4. Shell Programming and Scripting

Add Row from First Row (Split Row)

HI Guys, I have Below Input :- RepigA_hteis522 ReptCfiEtrBsCll_aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 RepigA ReptCfiEtrBsCll hteis522 aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 Split Data in two first row... (2 Replies)
Discussion started by: pareshkp
2 Replies

5. UNIX for Dummies Questions & Answers

Finding row number along with length of row

I have a fixed length file and I want to find out row number along with row length. I have a program that give me the line length if it satisfy the condition; but i would like to add row number as well? How do I do that? while IFS= read -r line; do if ; then echo ${line} echo... (8 Replies)
Discussion started by: princetd001
8 Replies

6. UNIX for Dummies Questions & Answers

Finding files with one row then moving them

Hi guys can you please help me with a script to find files with one row the move the file to another directory the files are in /optima/prd/optdir/ZTE_BSS/Combiner/ZTE_2G/out/BSC_PS_Basic_Meas and I want to move them to /optima/prd/optdir/ZTE_BSS/Loader/error/ZTE_2G/BSC_PS_Basic_Meas ... (5 Replies)
Discussion started by: Dj Moi
5 Replies

7. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 Replies

8. Shell Programming and Scripting

Finding Minimum value per Row range of data

Here is an example of a file I am working with: C 4704 CB 1318 ASP 115 BGRF 1 weak 0.0% 4.33 C 4720 OD 1322 ASP 115 BGRF 1 weak 0.0% 3.71 O 4723 OD 1322 ASP 115 BGRF 1 weak 0.0% 3.48 O 4723 CG 1321 ASP 115 BGRF 1 weak 0.0% 4.34... (3 Replies)
Discussion started by: userix
3 Replies

9. UNIX for Advanced & Expert Users

Finding last row

Using Linux and Bash, I have a script that outputs filenames with complete path, like this:I would like the following output:And I would like to get the filenames only. Tricky part is that I cannot predict how many levels deep the filename is located, so I cannot use standard Bash-kungfu to solve... (7 Replies)
Discussion started by: indo1144
7 Replies

10. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies
Login or Register to Ask a Question