Need the line number of failed records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need the line number of failed records
# 8  
Old 12-20-2011
Also please suggest if the error'd string can also added in the output with appropriate message as below (I did not request for this previously):

column 4 in file1.txt having value 6 and column 7 in file2.txt does not match

Code:
=>      awk -F',' -v file1="$1" -v file2="$2" 'NR == FNR {a[$1,$2,$3,$4]++;count++;next} !(a[$1,$3,$6,$7]){print FNR FS $0}' OFS="," 1.txt 2.txt
2,7000,john,2,0,0,1,7
3,7000,john,2,0,0,1,8
4,7000,john,2,0,0,1,9
8,7003,mike,1,0,0,2,2
9,7003,mike,1,0,0,2,3
10,7003,mike,1,0,0,2,4
11,8001,nike,1,2,4,1,8
12,8002,paul,2,0,0,2,7

# 9  
Old 12-20-2011
Your requirement isn't very clear, I'm afraid. Isn't that the same output as before?
# 10  
Old 12-20-2011
Currently, only the non matching values in file2 with file1 is getting displayed without any information about the file1 values. I actually requested for help on the output such that the exact failure place during a match between a value in file1 with file2 is displayed for user. I mean more information regarding the failure.
# 11  
Old 12-20-2011
What kind of information? You already have all the file1 values in the output (since they matched the file2 columns).

Give some example input/output...
# 12  
Old 12-20-2011
Code:
[carun@fattony] /u/carun/MTNN>
=> cat file2.txt
7000,2,1,6
7001,2,1,7
7002,2,1,6
7003,1,2,1

[carun@fattony] /u/carun/MTNN>
=> cat file1.txt
7000,2,1,6
7001,2,1,7
7002,2,1,6
7003,1,2,5

=> awk -F',' -v file1="$1" -v file2="$2" 'NR == FNR {a[$1,$2,$3,$4]++;count++;next} !(a[$1,$2,$3,$4]){print FNR FS $0}' OFS="," file2.txt file1.txt
4,7003,1,2,5

Now currently the output shows the lines in file2.txt which does not match with file1.txt

So, the expected output is as below :

Code:
Comparing 5 in file1.txt in column 4 in line 4 does not match with 1 in file2.txt with column 4 in line 4

---------- Post updated at 07:52 PM ---------- Previous update was at 04:47 PM ----------

Hi Gurus,

Can someone please help me on this ? I am kind of struck here and unable to proceed.

Thank you.

Last edited by arunshankar.c; 12-20-2011 at 08:35 AM.. Reason: Incomplete output information
# 13  
Old 12-20-2011
Well, line 4 of file 1 doesn't match line 1 column 1 of file2, line 1 column 2 of file2, line 1 column 3 of file2, etc. Do you really want all that output?

Otherwise you'll need to define which file2 line you think should have been the match (e.g. because column 1 matches).

Last edited by CarloM; 12-20-2011 at 12:45 PM..
# 14  
Old 12-20-2011
Code:
=> cat file2.txt
7000,2,1,6
7001,2,1,7
7002,2,1,6
7003,1,2,1

[carun@fattony] /u/carun/MTNN>
=> cat file1.txt
7000,2,1,6
7001,2,1,7
7002,2,1,6
7003,1,2,5

awk -F',' -v file1="$1" -v file2="$2" 'NR == FNR {a[$1,$2,$3,$4]++;count++;next} !(a[$1,$2,$3,$4]){print FNR FS $0}' OFS="," file2.txt file1.txt

Output displayed :
4,7003,1,2,5

My understanding in the above awk is that it checks the line 1 column 1,2,3,4 of file2.txt with line1 column 1,2,3,4 of file1.txt
initially. This continues till 4th line and then the awk finds that line4 of file2.txt does not match with line4 of
file1.txt

So, in the output, the 4th line of file1.txt is displayed since there is a mismatch (the ones have marked as magenta). Please correct if my understanding is incorrect

Now, the output that I wanted is to state to user that :

Comparing column 4 of line 4 in file2.txt having value 1 does not match with column 4 of line 4 in file1.txt having value 5
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

2. Shell Programming and Scripting

adding line number to *end* of records in file

Given a file like this: abc def ghi I need to get to somestandardtext abc1 morestandardtext somestandardtext def2 morestandardtext somestandardtext ghi3 morestandardtext Notice that in addition to the standard text there is the line number added in as well. What I conceived is... (4 Replies)
Discussion started by: edstevens
4 Replies

3. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

4. Shell Programming and Scripting

Write $line number into textfile and read from line number

Hello everyone, I don't really know anything about scripting, but I have to manage to make this script, out of necessity. #!/bin/bash while read -r line; do #I'm reading from a big wordlist instructions using $line done Is there a way to automatically write the $line number the script... (4 Replies)
Discussion started by: bobylapointe
4 Replies

5. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

6. UNIX for Dummies Questions & Answers

How to read contents of a file from a given line number upto line number again specified by user

Hello Everyone. I am trying to display contains of a file from a specific line to a specific line(let say, from line number 3 to line number 5). For this I got the shell script as shown below: if ; then if ; then tail +$1 $3 | head -n $2 else ... (5 Replies)
Discussion started by: grc
5 Replies

7. Shell Programming and Scripting

how to get the data from line number 1 to line number 100 of a file

Hi Everybody, I am trying to write a script that will get some perticuler data from a file and redirect to a file. My Question is, I have a Very huge file,In that file I have my required data is started from 25th line and it will ends in 100th line. I know the line numbers, I need to get all... (9 Replies)
Discussion started by: Anji
9 Replies

8. Shell Programming and Scripting

Adding a columnfrom a specifit line number to a specific line number

Hi, I have a huge file & I want to add a specific text in column. But I want to add this text from a specific line number to a specific line number & another text in to another range of line numbers. To be more specific: lets say my file has 1000 lines & 4 Columns. I want to add text "Hello"... (2 Replies)
Discussion started by: Ezy
2 Replies

9. Shell Programming and Scripting

Appending line number to each line and getting total number of lines

Hello, I need help in appending the line number of each line to the file and also to get the total number of lines. Can somebody please help me. I have a file say: abc def ccc ddd ffff The output should be: Instance1=abc Instance2=def Instance3=ccc Instance4=ddd Instance5=ffff ... (2 Replies)
Discussion started by: chiru_h
2 Replies

10. UNIX for Advanced & Expert Users

delete records using line number(NR)

Hai I have a flat file which contains more than 6 crore lines or records. I want to delete only one line, using line number. For example I want to delete 414556 th line . How to do this using sed or awk command. thanks (3 Replies)
Discussion started by: tkbharani
3 Replies
Login or Register to Ask a Question