- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: seach two files
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 05:19 AM
02-17-2005 05:19 AM
I need to read a file (allfiles.txt) and for each record in the file, search another file (arc.txt) to see if there is a match. If there is no match then echo the record from allfiles.txt to the screen.
There are approx 80,000 records in each file.
The script below works but is slow.
Is there a faster way. ?
Thanks
for i in `cat /tmp/allfiles.txt`
do
grep -q $i /tmp/arc.txt
exit_status=$?
if [ $exit_status != 0 ]
then
echo $i
fi
done
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 05:33 AM
02-17-2005 05:33 AM
Solution#!/usr/bin/perl
@files=("/tmp/allfiles.txt","tmp/arc.txt");
for $i in (0..1) {
open(INP,"<$files[$i]");
while(
chomp;
$hold{$_}+=$i+1;
}
close(INP);
}
foreach $rec (sort keys %hold) {
$cnt=$hold{$rec};
next if $cnt == 3;
print "Only in allfiles: ".$rec,"\n" if $cnt == 1;
print "Only in arc : ".$rec,"\n" if $cnt == 2;
}
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 07:02 AM
02-17-2005 07:02 AM
Re: seach two files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 07:15 AM
02-17-2005 07:15 AM
Re: seach two files
grep -f /tmp/allfiles.txt /tmp/arc.txt will produce a line of output for each "hit" found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 07:18 AM
02-17-2005 07:18 AM
Re: seach two files
man diff
man sort
diff file1 file2
or
sort -u file1 file2
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 07:35 AM
02-17-2005 07:35 AM
Re: seach two files
the sort should read:
sort fileA fileB|uniq -u
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 07:49 AM
02-17-2005 07:49 AM
Re: seach two files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 07:52 AM
02-17-2005 07:52 AM
Re: seach two files
if they are not sorted then you are left to WALKING the files. There are no other options - period.
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 08:09 AM
02-17-2005 08:09 AM
Re: seach two files
> Well I'm getting closer, but I think I am making
> this too hard..
The hard part is not writing the script that does what you want (the script written by you in your
original post does that perfectly), the hard part is
writing one that is *significantly faster*.
If your script runs only few times, you should
continue to use the script you are using now.
Otherwise you could write a C or C++ program to
do what you want.
If you decide do this, write a a C /C++ program
that uses 2 char arrays to read the entire content
of both the files (i.e like char allfiles[][] and char
arc[][]) to the memory, sort them and start
searching from top.This will make searching
significantly faster as
1) you can abort searching for a string if strncmp()
returns greater than 1
2)search for a string in arc[][] should start where
the last search ended (i.e no need to search entire
string).
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 08:22 AM
02-17-2005 08:22 AM
Re: seach two files
If you want speed and lots of record create a C script. That always works.
Regards,
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 09:03 AM
02-17-2005 09:03 AM
Re: seach two files
for i in `cat /tmp/allfiles.txt`
since allfiles.txt has 80000 records.
Maybe you could try changing the "for" to a "while".
IFS=""
exec <4/tmp/allfiles.txt
while read -ru4 i ; do
grep -q $i /tmp/arc.txt
...
done
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2005 09:05 AM
02-17-2005 09:05 AM
Re: seach two files
exec 4
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-18-2005 05:19 AM
02-18-2005 05:19 AM
Re: seach two files
mkfifo fifo1
mkfifo fifo2
sort allfiles.txt > fifo1
sort arc.txt > fifo2
comm -12 fifo1 fifo2