Search files that all contain 4 specific words


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search files that all contain 4 specific words
# 1  
Old 01-21-2007
Search files that all contain 4 specific words

Hello,

I want an one line command that brings me back all the files in a folder that contain 4 specific words anywhere inside them.

I want to use find,xargs and grep. for example i know for one word the command would be:

find . | xargs grep 'Word1'

But i don't know for 4 specific words what i should do.

Thanx
# 2  
Old 01-21-2007
you can use egrep "word1|word2|word3|word4"
# 3  
Old 01-21-2007
thank you,
but i don't think that this is what i want.this will give me and the files that only contain word1 and not word2 and word3 and word4.

I want the files returned to contain all 4 words
# 4  
Old 01-21-2007
Try...
Code:
find . -type f | xargs perl -0 -n -e 'print $ARGV."\n" if /word1/&&/word2/&&/word3/&&/word4/'

# 5  
Old 01-22-2007
Well thank you very much,

but i don't want to use the command perl. I want to use the commands find,xargs and grep. Is it possible??
# 6  
Old 01-22-2007
try egrep

find . | xargs egrep "word1|word2|word3"
# 7  
Old 01-22-2007
thank you,
but i said to the previous post this is not what i want.this will give me and the files that only contain word1 and not word2 and word3 and word4.

I want the files returned to contain all 4 words.Also i want to use the commands find,xargs and grep.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Program to search for the files with specific format

Hi All, Your help on the below requirement is highly appreciated. I am building a program which should pick the file from a source directory and place them into target directory. While selecting the file in source it should look for some pattern in the file name. Ex: File Name 1:... (10 Replies)
Discussion started by: bharath561989
10 Replies

2. Shell Programming and Scripting

Search words in any quote position and then change the words

hi, i need to replace all words in any quote position and then need to change the words inside the file thousand of raw. textfile data : "Ninguno","Confirma","JuicioABC" "JuicioCOMP","Recurso","JuicioABC" "JuicioDELL","Nulidad","Nosino" "Solidade","JuicioEUR","Segundo" need... (1 Reply)
Discussion started by: benjietambling
1 Replies

3. UNIX for Beginners Questions & Answers

Non-root script used search and list specific key words

Hy there all. Im new here. Olso new to terminal & bash, but it seams that for me it's much easyer to undarsatnd scripts than an actual programming language as c or anyother languare for that matter. S-o here is one og my home works s-o to speak. Write a shell script which: -only works as a... (1 Reply)
Discussion started by: Crisso2Face
1 Replies

4. Shell Programming and Scripting

Search a test file for specific words

I have the need to search a text file from my unix script to determine if it contains the strings of: 'ERROR' and/or 'WARNING'. By using Grep I can search the file and return a where one of these strings exists. Like this: cat myfile.txt | grep ERROR Output: PROCESS ERROR HERE ... (3 Replies)
Discussion started by: buechler66
3 Replies

5. Shell Programming and Scripting

want to search for the words in the files

Hi Friends, I have been trying to write the script since morning and reached some where now. but i think i am stuck in the final step. please help I want to search the strings below in red in the be be searched in the directories below. How can i do that in my shell script. Thanks Adi ... (8 Replies)
Discussion started by: asirohi
8 Replies

6. Shell Programming and Scripting

search files without a specific text

Hi all, I need UNIX command that would give me all files without the string "4R" anywhere in the file. I have about a hundred files in my directory, and I need to list all files wihtout the string "4R" anywhere. Can anyone help me please? Thank you.l (4 Replies)
Discussion started by: risk_sly
4 Replies

7. Shell Programming and Scripting

search of common words in set of files

Hi, I have a set of simple, one columned text files (in thousands). file1: a b c d file 2: b c d e and so on. There is a collection of words in another file: b d b c d e I have to find out the set of words (in each row) is present or absent in the given set of files. So, the... (4 Replies)
Discussion started by: mala
4 Replies

8. UNIX for Dummies Questions & Answers

Search File for Specific Words

I have a file that contains the following: Mon Dec 3 15:52:57 PST 2o007: FAILED TO PROCESSED FILE 200712030790881200.TXT - exit code=107 Tue Dec 4 09:08:57 PST 2007: FAILED TO PROCESSED FILE 200712030790879200a.TXT - exit code=107 This file also has a lot more stuff since it is a log file.... (2 Replies)
Discussion started by: mevasquez
2 Replies

9. UNIX for Dummies Questions & Answers

How to search files containing a specific word in the content

Hi all, Lets say I have 3 files a.txt and b.txt and c.txt. a.txt has the following text ==================== apple is good for health b.txt has the following text ==================== apple is pomme in french c.txt has the following text ==================== orange has citric acid... (1 Reply)
Discussion started by: amjath78
1 Replies

10. UNIX for Dummies Questions & Answers

Search all files for specific string

Hi Friends, How can I search all files in all slices on a unix system for a particular string within the file. e.g search string 'oracle' Thanks (4 Replies)
Discussion started by: sureshy
4 Replies
Login or Register to Ask a Question