Sponsored Content
Top Forums Shell Programming and Scripting Need the line number of failed records Post 302583017 by arunshankar.c on Monday 19th of December 2011 10:25:34 AM
Old 12-19-2011
Code:
=> awk -F',' -v file1="$1" -v file2="$2" 'NR == FNR {a[$1,$2,$3,$4]++;next} !(a[$1,$2,$3,$4]); END{for(X in a) N++; print N }' OFS=","  1.txt 2.txt
7000,john,2,0,0,1,6
7000,john,2,0,0,1,7
7000,john,2,0,0,1,8
7000,john,2,0,0,1,9
7001,elen,2,0,0,1,7
7002,sami,2,0,0,1,6
7003,mike,1,0,0,2,1
7003,mike,1,0,0,2,2
7003,mike,1,0,0,2,3
7003,mike,1,0,0,2,4
8001,nike,1,2,4,1,8
8002,paul,2,0,0,2,7
10

Above is the output, i.e. the file2.txt is getting displayed. I actually needed the line number of failed lines. Please suggest

---------- Post updated at 08:55 PM ---------- Previous update was at 08:44 PM ----------

Quote:
Originally Posted by CarloM
Can't you just add FNR to your output?

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

This will print all the lines :
Code:
=> awk -F',' -v file1="$1" -v file2="$2" 'NR == FNR {a[$1,$2,$3,$4]++;next} !(a[$1,$2,$3,$4]) {print FNR FS $0}' OFS="," 1.txt 2.txt
1,7000,john,2,0,0,1,6
2,7000,john,2,0,0,1,7
3,7000,john,2,0,0,1,8
4,7000,john,2,0,0,1,9
5,7001,elen,2,0,0,1,7
6,7002,sami,2,0,0,1,6
7,7003,mike,1,0,0,2,1
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


Last edited by Scott; 12-19-2011 at 11:37 AM.. Reason: Code tags
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
h5diff(1)						      General Commands Manual							 h5diff(1)

NAME
h5diff - Compares two HDF5 files and reports the differences. SYNOPSIS
h5diff file1 file2 [OPTIONS] [object1 [object2 ] ] DESCRIPTION
h5diff is a command line tool that compares two HDF5 files, file1 and file2, and reports the differences between them. Optionally, h5diff will compare two objects within these files. If only one object, object1, is specified, h5diff will compare object1 in file1 with object1 in file2. In two objects, object1 and object2, are specified, h5diff will compare object1 in file1 with object2 in file2. These objects must be HDF5 datasets. object1 and object2 must be expressed as absolute paths from the respective file's root group. Additional information, with several sample cases, can be found in the document H5diff Examples. OPTIONS
file1 file2 The HDF5 files to be compared. -h Print all differences. -r Print only the names of objects that differ; do not print the differences. These objects may be HDF5 datasets, groups, or named datatypes. -n count Print difference up to count differences, then stop. count must be a positive integer. -d delta Print only differences that are greater than the limit delta. delta must be a positive number. The comparison criterion is whether the absolute value of the difference of two corresponding values is greater than delta (e.g., |a-b| > delta, where a is a value in file1 and b is a value in file2). -p relative Print only differences that are greater than a relative error. relative must be a positive number. The comparison criterion is whether the absolute value of the difference 1 and the ratio of two corresponding values is greater than relative (e.g., |1-(b/a)| > relative where a is a value in file1 and b is a value in file2). object1 object2 Specific object(s) within the files to be compared. EXAMPLES
The following h5diff call compares the object /a/b in file1 with the object /a/c in file2: h5diff file1 file2 /a/b /a/c This h5diff call compares the object /a/b in file1 with the same object in file2: h5diff file1 file2 /a/b And this h5diff call compares all objects in both files: h5diff file1 file2 SEE ALSO
h5dump(1), h5ls(1), h5repart(1), h5import(1), gif2h5(1), h52gif(1), h5perf(1) h5diff(1)
All times are GMT -4. The time now is 08:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy