Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

outer join in unix with 2 files

Posted on 2003-02-19
4
Medium Priority
?
369 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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

577 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