Performance issue with fgrep -vf file1 file2>file3


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Performance issue with fgrep -vf file1 file2>file3
# 1  
Old 08-15-2013
Question [Solved] Performance issue with fgrep -vf file1 file2>file3

Hi all,


My requirement is that i have two files file1 and file2. file1 content is present in file2. i want to have a final which will have file2 contents but not the contents of file1 so I am running below command.
Code:
fgrep -vf file1 file2>file3

no of records in file1 is 65282
no of records in file2 is 88187

and fgrep -v is taking 25Minutes to complete the operation
Is there any other way we can do same operation in less time?

Last edited by Franklin52; 08-16-2013 at 03:13 AM.. Reason: Please use code tags
# 2  
Old 08-15-2013
You could create a ram disk and place the files on the ram disk...then do the fgrep. Just a thought.
# 3  
Old 08-15-2013
Thanks blackrageous!! but i don't have privelege to access ram disk in office.. is there any other way using awk or sed??
# 4  
Old 08-15-2013
sort both files and use comm, or, if you are sure ALL file1 lines are found in file2, try sort -u file1 file2
# 5  
Old 08-15-2013
Hi RudiC

Please have a look at contents of files below.

file1
Code:
QC20011                         063890404       02002
QC20011                         059400669       02002
QC20011                         063309945       02002
QC20011                         064005208       02002
QC20011                         064426764       02002
QC20011                         070251327       02002
QC20011                         065565551       02006


file2
Code:
3       QC20011                         063890404       02002   JONES & CO MYA MIRROR CLOCK                              00000.00        00000.00        00000.00                       20130729        20130814
3       QC20011                         063890404       02007   JONES & CO MYA MIRROR CLOCK                              00000.00        00000.00        00000.00                       20130729        20130814
3       QC20011                         063890404       02012   JONES & CO MYA MIRROR CLOCK                              00000.00        00000.00        00000.00                       20130729        20130814
3       QC20011                         063890404       02015   JONES & CO MYA MIRROR CLOCK                              00000.00        00000.00        00000.00                       20130729        20130814
3       QC20011                         063890404       02017   JONES & CO MYA MIRROR CLOCK                              00000.00        00000.00        00000.00                       20130729        20130814
3       QC20011                         063890404       02019   JONES & CO MYA MIRROR CLOCK                              00000.00        00000.00        00000.00                       20130729        20130814


do you think comm or sort -u will work?

Last edited by Franklin52; 08-16-2013 at 03:14 AM.. Reason: Please use code tags
# 6  
Old 08-15-2013
I'm not sure that this will run faster than what you tried before, but nevertheless give it a shot:
Code:
awk 'NR==FNR {T[$1$2$3]; next} ($2$3$4 in T) {next} 1' file1 file2

This User Gave Thanks to RudiC For This Post:
# 7  
Old 08-15-2013
Great Thanks so much RudiC... Its worked and faster than previous completed within 2 Min only..

Can you please explain also below code what does that mean?
Code:
awk 'NR==FNR {T[$1$2$3]; next} ($2$3$4 in T) {next} 1' file1 file2


Last edited by Franklin52; 08-16-2013 at 03:15 AM.. Reason: Please use code tags for data and code samples
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to search field2 in file2 using range of fields file1 and using match to another field in file1

I am trying to use awk to find all the $2 values in file2 which is ~30MB and tab-delimited, that are between $2 and $3 in file1 which is ~2GB and tab-delimited. I have just found out that I need to use $1 and $2 and $3 from file1 and $1 and $2of file2 must match $1 of file1 and be in the range... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

awk or any other means to find IP (File1 / MAC (File2)) entries and putting them on File3

Hi everyone, I would like to complete the following could you please find some time and help me to achieve below: File 1 has a list of IP address (more than 1k) File1:1.1.1.1 2.2.2.2 1.1.1.2 3.3.3.3 2.3.3.2File 2 has content like this:Internet 11.165.91.244 0 Incomplete ... (4 Replies)
Discussion started by: redred
4 Replies

3. UNIX for Dummies Questions & Answers

Compare file1 and file2, print matching lines in same order as file1

I want to print only the lines in file2 that match file1, in the same order as they appear in file 1 file1 file2 desired output: I'm getting the lines to match awk 'FNR==NR {a++}; FNR!=NR && a' file1 file2 but they are in sorted order, which is not what I want: Can anyone... (4 Replies)
Discussion started by: pathunkathunk
4 Replies

4. UNIX for Dummies Questions & Answers

Copy(append ) the contents of file1 and file2 to file3

Platform : Oracle linux 6.5 I have two log files with the following contents # ls -l total 8 -rw-r--r--. 1 root root 75 Dec 10 20:55 myLogfile1.log -rw-r--r--. 1 root root 51 Dec 10 20:57 myLogfile2.log # # cat myLogfile1.log hello world jaded zombies acted quaintly but kept driving... (9 Replies)
Discussion started by: kraljic
9 Replies

5. Shell Programming and Scripting

awk read in file1, gsub in file2, print to file3

I'm trying to use awk to do the following. I have file1 with many lines, each containing 5 fields describing an individual set. I have file2 which is a template config file with variable space holders to be replaced by the values in file1. I would like to substitute each set of values in file1 with... (6 Replies)
Discussion started by: msmehaffey
6 Replies

6. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

7. Shell Programming and Scripting

grep -f file1 file2

Hi I started to learn bash a week ago. I need filter the strings from the last column of a "file2" that match with a column from an other "file1" file1: chr10100036394-100038350AK077761 chr10100041065-100046547AK032226 chr10100041065-100046547AK016270 chr10100041065-100046547AK078231 ...... (6 Replies)
Discussion started by: geparada88
6 Replies

8. Shell Programming and Scripting

file1 newer then file2

Hello, I am new to shell scripting and i need to create a script with the following directions and I can not figure it out. Create a shell script called newest.bash that takes two filenames as input arguments ($1 and $2) and prints out the name of the newest file (i.e. the file with the... (1 Reply)
Discussion started by: mandylynn78
1 Replies

9. UNIX for Dummies Questions & Answers

cat file1 file2 > file3

file1 has pgap500 500 file2 has bunch of data cat file1 file2 > file3 cp file2 file3.dat then vi pgap500 500 onto 1st line compare file3 and fil3.dat, they are not the same. any idea ? the 1st line, i want to put pg500 xxx ---------- Post updated at 07:35 AM ---------- Previous... (2 Replies)
Discussion started by: tjmannonline
2 Replies

10. UNIX for Dummies Questions & Answers

echo "ABC" > file1.txt file2.txt file3.txt

Hi Guru's, I need to create 3 files with the contents "ABC" using single command. Iam using: echo "ABC" > file1.txt file2.txt file3.txt the above command is not working. pls help me... With Regards / Ganapati (4 Replies)
Discussion started by: ganapati
4 Replies
Login or Register to Ask a Question