5 pts.
 Awk program to print output of comm command in required format
I have two files x and y containing two fields emp number and emp name in each file. I want to bring out the mismatching entries and missing entries into a file. File x has the correct emp number and emp name. y has correct emp number but name is not correct or blank or correct.  I used comm -13 x y > z1 and comm -13 x y >z2. The out put files now consists of unique fields in file x and file y. But i want the print output  as emp number , emp name in file1 , emp name in file2 for comparing the emp names. The x and y files has more than 50000 lines. I heard that through awk program we can do that but i couldn't achieve it. I could print either file z or file z1. but not combined output as required. I would be thankful if you guide me at the earliest. Thankyou sagar

Software/Hardware used:
linux, awk programs
ASKED: September 30, 2012  4:22 PM
UPDATED: October 1, 2012  12:03 PM

Answer Wiki:
Why don't use diff command? First, sort both files (I hope these are plain text): sort x > x_sorted sort y > y_sorted Then, diff sorted files: diff -wB x_sorted y_sorted -wB means ignore all blanks and blank lines in comparison. If it is necessary to double, etc. spaces and tabs and blank lines, use a variation: grep -v '^$' x | sed -r 's/[[:space:]]+/ /g' | sort > x_sorted grep -v '^$' y | sed -r 's/[[:space:]]+/ /g' | sort > y_sorted diff x_sorted y_sorted Good luck Petko
Last Wiki Answer Submitted:  November 26, 2012  5:44 pm  by  petkoa   3,120 pts.
All Answer Wiki Contributors:  petkoa   3,120 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Just very naievly assuming that the records in your two files z1 and z2 are in the same order, you can use ‘getline < “filename”‘ to read from a second file.
Again, with no testing, just displaying the content of the lines, try this:
BEGIN { num=” “ ; nam1=” “; nam2=” “ }{  num = $1 ; nam1 = $2 ;  getline < “file_z2″ ; nam2 = $2 ;  print num, “,  “, nam1,”,  “,nam2}END {}
If you need to check that the two read lines actually contain the same emp-num, it of course gets trickier….
Good Luck. 

 535 pts.

 
 35 pts.