find string from multiple dir and redirect to new files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find string from multiple dir and redirect to new files
# 1  
Old 03-30-2010
MySQL find string from multiple dir and redirect to new files

Hi,

I am new to script and I want find one string from multiple files in diff directories and put that out put to new file.

Like I have A,B & C directories and each has multiple files but one file is unic in all the directories like COMM.txt
Now I want write script to find the string "Jack" and what ever get the output lines need to redirect into my home directory

Hope i get help here....
# 2  
Old 03-30-2010
Do you want any specific action with unique file?
by the way,

Code:
find /path/to/parent/dir/of/A,B,C/ -type f  | xargs grep 'Jack' > $HOME/result.dat

# 3  
Old 03-30-2010
MySQL find string from multiple dir and redirect to new files

Yes, there is one more req with that. in sub directories, each dir has one file name with Jack.txt and other files are diff names. but i want to go to each sub dir's and search the string in only that file and when it get result it should create same file name in my home dir for each file search and put the result init.

Thanks for your help

Last edited by Mahessh123; 03-30-2010 at 07:01 PM..
# 4  
Old 03-31-2010
So you want to find only in 'Jack.txt' ?

Code:
find /path/to/parent/dir/of/A,B,C/ -type f -name "Jack.txt"  | xargs grep 'Jack' > $HOME/result.dat

# 5  
Old 03-31-2010
MySQL find string from multiple dir and redirect to new files

sorry for keep asking....
actually the file name in each dir is jack<yr>.txt and in each sub dir the file has with yr ext.
When it send the result to result.dat, all going into that file, but each file result should go to with same file name in home dir instead into single file

Thanks
# 6  
Old 04-01-2010
I am still confused.
your files are "jack<year>.txt" or with year extension eg jack.<year> ?
you wrote both the things.
Better give an example with the sample file names.

as per my understanding:
Code:
for file in $(find /path/to/parent/dir/of/A,B,C/ -type f -name "*.txt")
do
 grep 'Jack' $file > $HOME/$(basename $file).result
done

you can change the result file name whatever you want.
# 7  
Old 04-06-2010
MySQL find string from multiple dir and redirect to new files

Great.. its works perfect.
Thanks so much for you help on this
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a string and then return the next 20 characters in multiple files

Hello all, I have a directory with 2000+ files. I need to look in each file for an invoice number. To identify this, i can search for the string 'BIG' and then retrieve the next 30 characters. I was thinking awk for this, but not sure how to do it. Each file contains one long string and in... (8 Replies)
Discussion started by: jdinero
8 Replies

2. Shell Programming and Scripting

Script to find & replace a multiple lines string across multiple php files and subdirectories

Hey guys. I know pratically 0 about Linux, so could anyone please give me instructions on how to accomplish this ? The distro is RedHat 4.1.2 and i need to find and replace a multiple lines string in several php files across subdirectories. So lets say im at root/dir1/dir2/ , when i execute... (12 Replies)
Discussion started by: spfc_dmt
12 Replies

3. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

4. Shell Programming and Scripting

How to find particular string in multiple files

Hello friends, I have find a paticular string from the files present in my user for example: a username and password is hardcoded in multiple files which present in the my user.so I have to search about username in which files it is available.there are several dirctories are there,so... (5 Replies)
Discussion started by: sivaranga001
5 Replies

5. Shell Programming and Scripting

How to find particular string in multiple files with in the current directory.

Hello friends, Plz suggest the find command, How to search a string in a paticular string in miltiple files with current dirctory.:) Thanks in advance. Siva Ranganath Ch (2 Replies)
Discussion started by: sivaranga001
2 Replies

6. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

7. Shell Programming and Scripting

replace string in multiple files, dir and subdir

Hello, I have a directory www with multiple directories. Every directory has site name with .htm, .html, .php files or sub directories with .htm, .php, .html file as example - www - sitename 1 - site 1 - sitename 2 - sitename 3 What I'm looking for is a... (7 Replies)
Discussion started by: andyjill
7 Replies

8. Shell Programming and Scripting

How to Pull out multiple files from DB table and redirect all those files to a differetn directory?

Hi everyone!! I have a database table, which has file_name as one of its fields. Example: File_ID File_Name Directory Size 0001 UNO_1232 /apps/opt 234 0002 UNO_1234 /apps/opt 788 0003 UNO_1235 /apps/opt 897 0004 UNO_1236 /apps/opt 568 I have to... (3 Replies)
Discussion started by: ss3944
3 Replies

9. Shell Programming and Scripting

shell script to find and replace string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (11 Replies)
Discussion started by: pharos467
11 Replies

10. UNIX for Dummies Questions & Answers

Find and replace a string in multiple files

I used the following script cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) ... (2 Replies)
Discussion started by: pharos467
2 Replies
Login or Register to Ask a Question