tags:

views:

67

answers:

5

hi guys i have two pipe delimited files,first file contains 1000 records and second file contains 10 records and records which are present in second file exists first file. Now need a file which which will give me 990 records by excluding 10 records which occur in both files,

i know how to this using SQL .But how can we acheive this in UNIX?

Any help greatly appreciated

+1  A: 

see the join command

Pierre
Thanks for the reply but it will work as inner join....i am looking for left outer join in UNIX
Anoop
+7  A: 

Suppose the files are all and some. Then do

 fgrep -v -f some all
Martin v. Löwis
+1 nice. I didn't know about -v.
kenny
hey martin it's working...Thanks for the Reply
Anoop
A: 

First, replace the pipes with newlines so we can process the files with line-oriented Unix tools. Then use comm to filter out the lines that appear in both files. Finally, convert the newlines back to pipes.

tr '|' '\n' < file1 | sort > file1.sorted
tr '|' '\n' < file2 | sort > file2.sorted
comm -3 file1.sorted file2.sorted | tr '\n' '|'

Or done all on one line using process substitution <(command) syntax:

comm -3 <(tr '|' '\n' < file1 | sort) <(tr '|' '\n' < file2 | sort) | tr '\n' '|'
John Kugelman
Hey John Thanks for the reply
Anoop
A: 

The comm utility can be used to filter lines from one file out of another

Ken Keenan
Hi Ken ..Thanks for the Reply
Anoop
A: 
awk 'FNR==NR{ a[$0++;next}(!($0 in a))' some all
ghostdog74