Link to home
Start Free TrialLog in
Avatar of yahrika
yahrika

asked on

outer join in unix with 2 files

I've 2 files :

file1
-----
496223224
497448063
497425608
497440502

file2
-----
A 20212 497448063
B 12141 497425608
C 18745 497440900

I'd like to have :

result_file (only record from file2 and not in file1)
-----------
C 18745 497440900



Thx in advance,
Yassin
Avatar of skian
skian


$ grep -v -f file1 file2

I think the -f option is not standard So only GNU grep
understands this.

Stephane
Avatar of yahrika

ASKER

This works great for a small file1 but if file2 is big

we have this error --> list too large

:(
ASKER CERTIFIED SOLUTION
Avatar of ellesd
ellesd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why not use join.  input must be sorted, so first,
  sort -n -o file1 file1
  sort -k 3n -o file2 file2
and then
  join -t ' ' -j1 1 -j2 3 -o 2.1,2.2,2.3 file1 file2
For those of us not overly fond of the bourne/ksh shell:

foreach i (`cat file1`)
  grep $i file2 >&/dev/null
  if( $status != 0 ) echo $i >>result_file
end

or if file1 is large

split file1
foreach x (x??)
  foreach i (`cat $x`)
    grep $i file2 >&/dev/null
    if( $status != 0 ) echo $i >>result_file
  end
  rm $x
end
Yeah, but it's hard to find aanyone who recommends programming in csh.  It's fine for "interactive" work but an abomination when one wants to do serious processing.
Like this?
join -1 1 -2 3 file1 file2 -v 2