how to grep a word from files in different folders


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to grep a word from files in different folders
# 1  
Old 07-16-2009
CPU & Memory how to grep a word from files in different folders

Hi,

I have 10 folders like a1,a2,a3...a10

each folder having 100 files.

how to grep a word from all the files in all folders at a time?
# 2  
Old 07-16-2009
Hi suresh,

try this -

find . -type d -name "a*" | xargs -i find {} -type f | xargs -i grep "your_word" {}

regards
# 3  
Old 07-16-2009
Hi
Its working, but I want the results with file name
# 4  
Old 07-16-2009
Quote:
Originally Posted by sanjay1979
Hi suresh,

try this -

find . -type d -name "a*" | xargs -i find {} -type f | xargs -i grep "your_word" {}

regards


You can try


find . -exec grep "your_word" '{}' \ ; -print

thanks
Pranab
# 5  
Old 07-17-2009
got error


find: 0652-018 An expression term lacks a required parameter.
ksh: -print: not found.

---------- Post updated 07-17-09 at 01:02 AM ---------- Previous update was 07-16-09 at 05:46 PM ----------

Any body plz help me...its a bit urgent

when I tried this command ,,
find . -type d -name "a*" | xargs -i find {} -type f | xargs -i grep "your_word" {}

I am getting the data.but i am unable to find the file/folder name.

key word : 123

required output

folder,file,keyword
a1,file1:123
a5,file4:123
a10,file3:123
# 6  
Old 07-17-2009
Did you try:
Code:
grep -R "pattern" a*

# 7  
Old 07-17-2009
This worked for me :

Code:
find . -type f -name "a*" -print | xargs grep "xyz"  /dev/null

I got it from man pages of "grep"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash directory loop, but only choose those folders with specific word in it

Hello, how in bash i can get directory loop, but only choose those folders with specific word in it, so it will only echo those with specific word #!/bin/bash for filename in /home/test/* do if ; then echo $filename; fithx! (4 Replies)
Discussion started by: ZerO13
4 Replies

2. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

3. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

4. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

5. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

6. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

7. Shell Programming and Scripting

Grep out specific word and only that word

ok, so this is proving to be kind of difficult even though it should not be. say for instance I want to grep out ONLY the word fkafal from the below output, how do I do it? echo ajfjf fjfjf iafjga fkafal foeref afoafahfia | grep -w "fkafal" If i run the above command, i get back all the... (4 Replies)
Discussion started by: SkySmart
4 Replies

8. Shell Programming and Scripting

grep one word in two files

Hi All, Can we grep one word in two file at same time. i.e using one command only. for ex egrep -i "word" file1 file2 is it possible? (1 Reply)
Discussion started by: sam25
1 Replies

9. Shell Programming and Scripting

how to grep word from .gz files & .z files

Hi I have find some account numbers from .gz files. There thousands of .gz files, also i am unable to grep .gz / .z files. I want to find file names & and those lines from list. Could you pls tell me / give me any syntax for finding word from ,gz files using grep? Thanks in advance (8 Replies)
Discussion started by: udaya_subbu
8 Replies

10. UNIX for Dummies Questions & Answers

how to grep for a word and display only the word

Hi, When we "grep" for a word in a file, it returns the lines containing the word that we searched for. Is there a way to display only the words and not the entire line containing them. Thanks Ananth (6 Replies)
Discussion started by: ananthmm
6 Replies
Login or Register to Ask a Question