Need a script to search and combine to a file

February 9, 2011 at 18:10:41
Specs: Unix
Hi Experts,

Need a script to search for all files in a directory that contain certain string eg:- "Create", "Delete" and combine all these files that contain the string to a single file.

Any advise?
Thanks for all the help.

See More: Need a script to search and combine to a file

Report •

February 9, 2011 at 22:04:39
Look at the man pages for the grep command. The grep command's -l option prints only the file names with matching lines.

Report •

February 11, 2011 at 02:00:31
Thanks for the information, nails.
I am able to search for a single string as follows:-
find /<directory> -exec grep -l CREATE {} \;

How do I do it for a string of words eg:- create, delete, grant etc without variables?

Thanks for the help.

Report •

February 11, 2011 at 09:47:29
The extended version of grep, egrep, supports regular expressions:

egrep -l "create|grant|delete" *.txt

The above command searches for create or grant or delete in all files ending with a txt extension.

Depending on your version of *nix, the regular grep command may already support regular expressions. My Solaris system does not.

Also, grep's -i switch ignores case.

Report •

Related Solutions

March 8, 2011 at 22:53:31
if the required field is present in many lines and somewhere it is having substrings separated with |

Report •

Ask Question