The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 04-22-2009
pinnacle pinnacle is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 182
Quote:
Originally Posted by vgersh99 View Post
Say 'few fields from file B' means fields 1, 3 and 5

Code:
nawk -F, 'FNR==NR{a[$4]= $3 OFS $4 OFS $5 OFS $6 OFS $7;next} $1 in a{print a[$4] OFS $1 OFS $3 OFS $5}' OFS=, fileA fileB

Its giving wrong output and i figured it out :
It is because of duplicate in field 4 of fileA and $1 field in fileB will also have duplicates.

Say suppose file A in 4th field has 2 times
ABC
ABC


And fileB in 1st field has 7 times
ABC
ABC
ABC
ABC
ABC
ABC
ABC
Hence my output file should have 14 times ABC
But i am getting ABC only 7 times.

Appreciate help