Script to find all the files that contain any of the words present in another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to find all the files that contain any of the words present in another file
# 1  
Old 05-20-2008
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  
Old 05-20-2008
you mean IN the files contents or in the filenames?
# 3  
Old 05-20-2008
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  
Old 05-21-2008
for i in `cat Full_path_of_D2/M1`
do
grep -l $i Full_path_of_D1/*
done

Thanks
Penchal
# 5  
Old 05-21-2008
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk code to find difference in second file which is not present in first file .

Hi All, I want to find difference between two files and output only lines which are not present in second file .I am using awk and I am getting only the first difference but I want to get all the lines which are not present in file2 .Below is the code I am using . Please help to get the desired... (7 Replies)
Discussion started by: srinivasrao
7 Replies

2. UNIX for Beginners Questions & Answers

UNIX script to append multiple text files into one file based on pattern present in filaname

Hi All-I am new to Unix , I need to write a script. Can someone help me with a requirement where I have list of files in a directory, I want to Merge the files if a pattern of string matches in filenames? AAAL_555A_ORANGE1_F190404.TXT AAAL_555A_ORANGE2_F190404.TXT AAAL_555A_ORANGE3_F190404.TXT... (6 Replies)
Discussion started by: Shankar455
6 Replies

3. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

4. UNIX for Dummies Questions & Answers

How to find a string that is present in the file or not?

Im pretty new to shell scripting, but i have got the jist of it over the past 10 weeks or so i have been using it. I just have one thing im stuck on thats bugging the hell out of me. Here it goes... I need a script that - You enter a filename and then a string which reports whether that string... (2 Replies)
Discussion started by: Waggie14
2 Replies

5. Shell Programming and Scripting

Script to list files not present in audio.txt file

I am having following folder structure. /root/audios/pop /root/audios/jazz /root/audios/rock Inside those pop, jazz, rock folders there are following files, p1.ul, p2.ul, p3.ul, j1.ul, j2.ul, j3.ul, r1.ul, r2.ul, r3.ul And I have a file named as "audio.txt" in the path /root/audios,... (11 Replies)
Discussion started by: gopikrish81
11 Replies

6. Shell Programming and Scripting

cp RAW files if JPEG file present

hi guys and girls, i have a folder containing RAW and JPG images. eg... 001.jpg 003.jpg 005.jpg 001.raw 002.raw 003.raw 004.raw 005.raw I want to copy only RAW files that have a corresponding JPG file in to a new folder. the jpg files do not need to be copied. in this example i... (6 Replies)
Discussion started by: fxylxy
6 Replies

7. Shell Programming and Scripting

Shell script to find out words, replace them and count words

hello, i 'd like your help about a bash script which: 1. finds inside the html file (it is attached with my post) the code number of the Latest Stable Kernel, 2.finds the link which leads to the download location of the Latest Stable Kernel version, (the right link should lead to the file... (3 Replies)
Discussion started by: alex83
3 Replies

8. UNIX for Dummies Questions & Answers

how to find common words and take them out from two files

Hi, everyone, Let's say, we have xxx.txt A 1 2 3 4 5 C 1 2 3 4 5 E 1 2 3 4 5 yyy.txt A 1 2 3 4 5 B 1 2 3 4 5 C 1 2 3 4 5 D 1 2 3 4 5 E 1 2 3 4 5 First I match the first column I find intersection (A,C, E), then I want to take those lines with ACE out from yyy.txt, like A 1... (11 Replies)
Discussion started by: kaixinsjtu
11 Replies

9. Shell Programming and Scripting

find files with 2 or more words

I'm trying to find files that contain two or more specific words (e.g. all files with both "John" and "Mary" in them but not necessarily on the same line) but I don't know how to go about it. Maybe something like grep to find files with the first word, then grep the resulting set of files to find... (1 Reply)
Discussion started by: Anita
1 Replies

10. Shell Programming and Scripting

To find the count of records from tables present inside a file.

hi gurus, I am having a file containing a list of tables.i want to find the count of records inside thes tables. for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file. ... (1 Reply)
Discussion started by: navojit dutta
1 Replies
Login or Register to Ask a Question