Finding files which contains anyone from the given patterns


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding files which contains anyone from the given patterns
# 8  
Old 11-06-2012
Quote:
Originally Posted by Rishi26
find . -type f - exec fgrep aa.txt {} \;
I see unwanted spaces. Can you copy & paste my command as it is and re-try?
This User Gave Thanks to Yoda For This Post:
# 9  
Old 11-06-2012
i have changed grep -f to fgrep as it is giving an error .
and i have run your command again and it didnt gave any response.

---------- Post updated at 12:57 AM ---------- Previous update was at 12:33 AM ----------

@bipinajith: if i am executing it with string( pattern "123")
then it is giving lines of code and not the file name
and if i give the pattern in aa.txt then it is not giving output.
# 10  
Old 11-08-2012
Thanks
now my requirement has been changed.
the output file should contain out_pattern.txt as its name
eg out_123.txt .
can you help me in that?

Last edited by Rishi26; 11-08-2012 at 01:04 AM..
# 11  
Old 11-08-2012
Try something like this..

Code:
for file in *
do
while read line
do
grep "$line" "$file" >> out_"$line"
done<search_pattern
done

This User Gave Thanks to pamu For This Post:
# 12  
Old 11-08-2012
Great
thanks a lot

now i have to find recursively in the folders.

super like
# 13  
Old 11-08-2012
Quote:
Originally Posted by Rishi26
now i have to find recursively in the folders.
Try something like this..

Give your path below...

Code:
for file in $(find /path/ -type f)
do
while read line
do
grep "$line" "$file" >> out_"$line"
done<search_pattern
done

Code:
find /path/ -type f | while read file 
do
while read line
do
grep "$line" "$file" >> out_"$line"
done<search_pattern
done


Last edited by pamu; 11-08-2012 at 04:49 AM.. Reason: corrected..
This User Gave Thanks to pamu For This Post:
# 14  
Old 11-08-2012
use

Code:
 
find /path/ -type f

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Find files excluding file patterns and subfolder patterns

Hello. For a given folder, I want to select any files find $PATH1 -f \( -name "*" but omit any files like pattern name ! -iname "*.jpg" ! -iname "*.xsession*" ..... \) and also omit any subfolder like pattern name -type d \( -name "/etc/gconf/gconf.*" -o -name "*cache*" -o -name "*Cache*" -o... (2 Replies)
Discussion started by: jcdole
2 Replies

2. Shell Programming and Scripting

Finding matching patterns in two files

Hi, I have requirement to find the matching patterns of two files in Unix. One file is the log file and the other is the error list file. If any pattern in the log file matches the list of errors in the error list file, then I would need to find the counts of the match. For example, ... (5 Replies)
Discussion started by: Bobby_2000
5 Replies

3. Shell Programming and Scripting

How to group matched patterns in different files

Hi, I have a master file that i need to split into multiple files based on matched patterns. sample of my data as follows:- scaff_1 a e 123 130 c_scaff_100 scaff_1 a e 132 138 c_scaff_101 scaff_1 a e 140 150 ... (2 Replies)
Discussion started by: redse171
2 Replies

4. Shell Programming and Scripting

Finding several patterns and outputting 4 lines after

I an trying to parse a file looking for pattern1, or pattern2, or pattern3 and when found print that line and the next 4 lines after it. I am using korn shell script on AIX and grep -A isn't available. (1 Reply)
Discussion started by: daveisme
1 Replies

5. Shell Programming and Scripting

Finding patterns in a file

Hi, I have a file with 3 columns and I want to find when the average number of rows on column 3 is a certain value. The output will be put into another file indicating the range. Here is what I mean (file is tab separated): hhm1 2 0 hhm1 4 0.5 hhm1 6 0.3 hhm1 8 -1.4... (2 Replies)
Discussion started by: kylle345
2 Replies

6. Shell Programming and Scripting

Need help with awk tool - finding text between two patterns

This is regarding using awk tool to find lines matching between 2 patterns. cat file | awk '/pat1/,/pat2/' But it's not working as expected in the following case. If pat1 also comes after pat2 then it's matching whole file after pat1. e.g. # > cat -n file 1 First line... (3 Replies)
Discussion started by: anand_bh
3 Replies

7. Shell Programming and Scripting

finding and removing patterns in a large list of urls

I have a list of urls for example: Google Google Base Yahoo! Yahoo! Yahoo! Video - It's On Google The problem is that Google and Google are duplicates as are Yahoo! and Yahoo!. I'm needing to find these conical www duplicates and append the text "DUP#" in from of both Google and... (3 Replies)
Discussion started by: totus
3 Replies

8. UNIX Desktop Questions & Answers

how to search files efficiently using patterns

hi friens, :) if i need to find files with extension .c++,.C++,.cpp,.Cpp,.CPp,.cPP,.CpP,.cpP,.c,.C wat is the pattern for finding them :confused: (2 Replies)
Discussion started by: arunsubbhian
2 Replies

9. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

10. Shell Programming and Scripting

Finding patterns through out all subdir

Hi all experts, here is a problem which i would appreciate ur expertise. I need to do this: Eg. Find a number: 1234567 which i dunno which file and which folder I do know which main folder it is in but it is hidden deep within a lot of subdir. Is it possible to find the file? + output... (4 Replies)
Discussion started by: unnerdy
4 Replies
Login or Register to Ask a Question