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
find files with 2 or more words Anita Shell Programming and Scripting 1 04-23-2008 12:44 PM
script to Read Error,jbase,voilation,segmentation words from a file Mujtaba khan Shell Programming and Scripting 3 03-30-2008 01:19 PM
To find the count of records from tables present inside a file. navojit dutta Shell Programming and Scripting 1 08-29-2007 11:04 AM
how to find capital letter names in a file without finding words at start of sentence kev269 Shell Programming and Scripting 1 04-10-2006 09:35 PM
PERL: print if files present perleo Shell Programming and Scripting 2 03-04-2003 03:53 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 05-20-2008
tsanthosh tsanthosh is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
Script to find all the files that contain any of the words present in another file

Hi All,

I am new to UNIX and shell scripts and also new to this forum.

I need a script to find all the files in a directory that contain any of the strings present in another file.

Please provide me the script or if you could provide pointers to any link in this forum it would be helpful.


Thanks,
TSK
  #2 (permalink)  
Old 05-20-2008
scarfake scarfake is offline
Registered User
  
 

Join Date: May 2008
Posts: 43
you mean IN the files contents or in the filenames?
  #3 (permalink)  
Old 05-20-2008
tsanthosh tsanthosh is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
IN the file contents.

Say I have files f1,f2,f3,f4,f5 in a directory D1.

The files have these strings respectively in their contents.

f1 - 0024020080520
f2 - 0015020080520
f3 - 0020020080520
f4 - 0010020080520
f5 - 0030020080520

Now, say I have another file M1 in another directory D2 which contains the following strings.

0024020080520
0015020080520
0010020080520

The script I am looking for needs to read file M1 fromD2 and search D1 for the files that contain the string in its contents and list the names of f1,f2 and f4.

Hope, I am clear now.

Sorry for not putting it clearly in the first place.

Thanks,
TSK
  #4 (permalink)  
Old 05-21-2008
penchal_boddu penchal_boddu is offline
Registered User
  
 

Join Date: Apr 2008
Location: Bangalore
Posts: 127
for i in `cat Full_path_of_D2/M1`
do
grep -l $i Full_path_of_D1/*
done

Thanks
Penchal
  #5 (permalink)  
Old 05-21-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,086
Code:
while read line
do
	for i in *
	do
		grep $line $i 1>/dev/null
		if [ $? -le 0 ]
		then
			echo $i
		fi
	done
done < checkfile
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 10:32 PM.


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