script to return records which are not matching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to return records which are not matching
# 1  
Old 10-11-2011
Java script to return records which are not matching

file1
Code:
abcd
efgh
ijkl
mnop

file2
Code:
mnop
qrst
uvwx
xyza

file3
Code:
1234
4567
7890

searchRecords
Code:
abcd
azyx
4567
aaaa

file1, file2, file3 aret the source files. I want to search the records in the file searchRecords. The records which are not present in source files should be my output.
With the above example, expected output is
output
Code:
azyx
aaaa

Moderator's Comments:
Mod Comment Please use code tags

Last edited by zaxxon; 10-24-2011 at 08:37 AM.. Reason: code tags, see PM
# 2  
Old 10-11-2011
what you have tried so far ..
# 3  
Old 10-11-2011
If I've understood your logic, you want to find records in file searchRecords that are not in any of file, file2 or file3

You can acheive this like this:-
Code:
sort -u file1 file2 file3 > mergedfile
grep -vf mergedfile searchRecords

This will merge all the first three files (removing duplicates) and then find all records in searchRecords which are not in the combined file mergedfile.



I hooe that this helps, but if I have the logic wrong, please correct me.


Robin
Liverpool/Blackburn
UK
# 4  
Old 10-11-2011
Data

yes you have understood my problem well.... But below error is coming up when trying the command

Code:
bash-3.00$ grep -vf MergedFile searchRecords
 
 
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .


Last edited by zaxxon; 10-24-2011 at 08:37 AM.. Reason: code tags
# 5  
Old 10-11-2011
Oh, I forgot that the options may be OS specific. Have a read of the man page for fgrep instead. Perhaps you just need:-
Code:
sort -u file1 file2 file3 > mergedfile
fgrep -v mergedfile searchRecords

.... instead.


Good luck!

Robin
Liverpool/Blackburn
UK
# 6  
Old 10-20-2011
Data

I tried the above commands and get below output
Code:
$ sort -u file1 file2 file3 > mergedfile
$ fgrep -v mergedfile searchRecords
abcd
azyx
4567
aaaa

but the expected output is
Code:
azyx
aaaa

Smilie

Last edited by zaxxon; 10-24-2011 at 08:38 AM.. Reason: code tags
# 7  
Old 10-21-2011
Use -f option in fgrep
Code:
$ fgrep -vf mergedfile searchRecords
azyx
aaaa
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Matching fields between two files, repeated records

In two previous posts (here) and (here), I received help from forum members comparing multiple fields across two files and selectively printing portions of each as output based upon would-be matches using awk. I had been fairly comfortable populating awk arrays with fields and using awk's special... (3 Replies)
Discussion started by: jvoot
3 Replies

2. UNIX for Advanced & Expert Users

Ufsdump Records in/out not matching

Hello, I'm on a Solaris 10 and doing backup using a tape. The records in/out are way off but with no other errors. Is that normal? What could be wrong? Thanks in advance! Steve --------------------- ufsdump 0f - /dev/dsk/c0d0s0 2>> /var/log/backupOS.log | ssh myhost dd... (1 Reply)
Discussion started by: steve041
1 Replies

3. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

4. Shell Programming and Scripting

To get Non matching records for current day

My objective is to get the non matching records of previous day with current day. eg, file1 contains 1 a 2 b and file2 contains: 2 b 3 c then expected output is 3 c¨ another example file 1 contains: 1 a 2 b file 2 contains 1 c 2 b (8 Replies)
Discussion started by: newbie2014
8 Replies

5. Shell Programming and Scripting

awk pattern matching name in records

Hi, I'm very new to these forums. I was wondering if someone could help an AWK beginner with a pattern matching an actor to his appearance in movies, which would be stored as records. Let's say we have a database of 4 movies (each movie a record with name, studio + year, and actor fields with... (2 Replies)
Discussion started by: Jill Ceke
2 Replies

6. Shell Programming and Scripting

Shell script matching similar records

hello all, I have requirement to identify similar records matching about 80% to 90%.I have to black list customers with multiple accounts. The data is in the Oracle Database, but is there any way I can get the data into flat file and compare the strings and fetch similar matching records? ... (2 Replies)
Discussion started by: kashik786
2 Replies

7. Shell Programming and Scripting

Common records after matching on different columns

Hi, I have the following files. cat 1.txt cat 2.txt output.txt The logic is as follows.... (10 Replies)
Discussion started by: jacobs.smith
10 Replies

8. UNIX for Dummies Questions & Answers

Find records with matching patterns

Hi, I need to find records with a search string from a file. Search strings are provided in a file. For eg. search_String.txt file is like below chicago mexico newark sanhose and the file from where the records need to be fetched is given below src_file:... (1 Reply)
Discussion started by: sbhuvana20
1 Replies

9. Shell Programming and Scripting

Removing non matching records

Hi all I have a file with records starting with "Page" has a first column. some of the records have some other junk characters has first column. so pls help me to remove rows which is not having "Page" has a first column. Thanks, Baski (2 Replies)
Discussion started by: baskivs
2 Replies

10. Shell Programming and Scripting

extract set of matching records

i have a pipe delimited file with records spread in many lines. i need to extract those records 1)having X in beginning of that record 2)and having at least one Y in beginning before other record begins eg: X|Rec1| A|Rec1| Y|Rec1| X|Rec2| Y|Rec2| Z|Rec3| X|Rec4| M|Rec4| ... (4 Replies)
Discussion started by: finder255
4 Replies
Login or Register to Ask a Question