# Grep content for multiple files

My OS is Sun Solaris. SunOS sintscdldmu001 5.11 11.3 sun4v sparc sun4v

I gave the command alter database backup controlfile to trace; and happened to forget it.

When i needed the contents of the controlfile, I started to search it. Now i want to something similar to grep *.trc | grep -i 'CONTROLFILE'

What is the right command to find under which file i have my control file contents under?

grep -l


That will print the name of the file and matching lines. It won't repeat the filename for multiple matchies.

If the string that you want to find is CONTROLFILE then you can just do this:

grep -li CONTROLFILE /path/to/trcfiles/*


That will output the names and the matching lines of the files containing the string CONTROLFILE. If that string is in the .trc file and that's all you want to return then pipe that to the end of the command.

grep -li CONTROLFILE /path/to/trcfiles/* | grep *.trc


If you want to search the keyword 'controlfile' in rest of the files then use the below command , note -i makes the search case insensitive

grep -i "controlfile" *.trc


but if controlfile is a file which has some patterns to be searched in rest of the files then you will have to pass the contents of controlfile like below

grep -f controlfile *.trc


this will search for the contents of controlfile in rest of the trc files.

If you're in the same folder where your files are present then just give *.trc as the last parameter else give the absolute/ relative path accordingly. and if you want to take your search recursively for the files present in rest of the folders starting from your path then use -r parameter.

You can use like below to identify which file contains your search text

grep -il <control file entry> <path where   trc files are located> *