?
Solved

outer join in unix with 2 files

Posted on 2003-02-19
4
Medium Priority
?
368 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:yahrika
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:liddler
ID: 7982257
Think this will work:

#!/bin/ksh
cat /dev/null > diff_file
{ while read LINE
do
awk "/${LINE}/ {print }" file2 >> diff_file
done
} < file1
comm -23 file2 diff_file >result_file


Tested it on solaris, but should be generic
0
 
LVL 2

Accepted Solution

by:
ellesd earned 60 total points
ID: 7982688
I'm not sure if the comm command will work since the lines in both files are complete different.  However, this short script will create the desired result_file:

cp file2 result_file
exec 3< file1
while read N <&3
do
  grep -v $N restult_file > tmpfile$$
  mv tmpfile$$ result_file
done
rm -f tmpfile$$

The last line (rm -f tmpfile$$) is not really needed, but I put it in as a safeguard.

Try it out and let me know.
0
 

Author Comment

by:yahrika
ID: 7985955
1st solution:

When i try with a big file test seems won't work
file2 --> 1763 record
file1 --> 226 record

diff_file --> 7060 records
result_file --> 0

2nd Solution :
When i try this --> error message (grep: can't open restult_file)



Help me please
0
 
LVL 2

Expert Comment

by:ellesd
ID: 7987829
Sorry, I misspelled it.  Just change it to result_file.
Again, I appologize.
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question