Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: fi
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 8 Topic 2135 of 2376
Post > Topic >>

Re: fi

by Ed Morton <morton@[EMAIL PROTECTED] > Jan 18, 2008 at 08:48 AM

On 1/18/2008 8:19 AM, Ed Morton wrote:
> 
> On 1/18/2008 3:23 AM, Madhur wrote:
> 
>>I would like to know the best way of generating filter of two files
>>based upon the following condition
>>
>>I have two files. Contents of the first file is
>>
>>File 1
>>abc def hij
>>asd sss lmn
>>hig pqr mno
>>
>>
>>File 2
>>
>>jih def asd
>>poi iuu wer
>>wer pqr jjj
>>
>>I would like have the output as
>>Output
>>
>>File1
>>asd sss lmn
>>File2
>>poi iuu wer
>>
>>Basically I want to compare the two files based on second column. If
>>the second
>>column matches on both the files do not print anything, else if there
>>is no matc
>>h in for the second column for first file in second file then print it
>>under Fil
>>e1 header, else if there is no match for the second column for second
>>file in fi
>>rst file print it under File2 header.
>>
>>Thankyou
>>Madhur
> 

Sorry, don't know what I was thinking earlier, try this:

awk '
NR==FNR { file2[$2] = $0; next }
$2 in file2 { file1[$2]; next }
{ delete file2[$2] }
END {
   print "File1"
   for (key in file1)
      print file1[key]
   print "File2"
   for (key in file2)
      print file2[key]
}' file2 file1

	Ed
 




 8 Posts in Topic:
fi
Madhur <madhurrajn@[EM  2008-01-18 01:23:44 
Re: fi
"Luuk" <luuk  2008-01-18 14:37:15 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 08:19:20 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 08:48:30 
Re: fi
"Luuk" <luuk  2008-01-18 16:25:33 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 11:03:33 
Re: fi
"Anton Treuenfels&qu  2008-01-18 20:02:49 
Re: fi
Ed Morton <morton@[EMA  2008-01-18 23:23:02 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 8:03:06 CDT 2008.