The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command to list large files search66 UNIX for Dummies Questions & Answers 13 12-11-2008 08:20 AM
Searching a specific line in a large file NIMISH AGARWAL Shell Programming and Scripting 4 07-10-2008 04:32 AM
Searching list of entries in file for actual files in dir not4google UNIX for Dummies Questions & Answers 2 10-18-2006 11:24 AM
viewing and searching large file Wrightman UNIX for Dummies Questions & Answers 1 04-29-2006 05:24 PM
List large files GNMIKE UNIX for Dummies Questions & Answers 2 12-28-2005 01:48 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-21-2009
Rhije Rhije is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 103
Searching for array in large list of files

I tried to make the title/subject detailed, but well.. have to keep it short as well.

I am wanting to take a large list of strings, and search through a large list of files to hopefully find numerous matches. I am not sure the quickest way to do this though.

Code:

// List of files

file1.txt
file2.txt
file3.txt
file4.txt
file5.txt
file6.txt
file7.txt

// Searches

testtag
strings
more stuff
lots of stuff here
So basically take all of the strings under // Searches, and search through the files listed above it. I could imagine that the script may go something like this..

Code:
find . -type f -size -100k | xargs egrep -il "(testtag|strings|more stuff|lots of stuff here)"
While I know that will work, I would like to find a more efficient way of doing it. Any help would be greatly appreciated
  #2 (permalink)  
Old 01-21-2009
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361

Put the search strings in a file and use the -f option to grep.
  #3 (permalink)  
Old 01-22-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,079
Code:
#!/usr/bin/perl
use strict;
sub find{
	my($file,$str)=(@_);
	open FH,"<$file";
	$str=~s/,/|/g;
	while(<FH>){
		print "$file [line $.]: $_" if /($str)/;
	}
	print "---------------\n";
	close FH;
}
my @arr=("a.txt","b.txt");
my $match="152178,014052";
map {find($_,$match)} @arr;
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0