Grep Command

Hi,

I have around 500 Text files and Each file will be having either

String1 or String2.

I want to list the file only which has String1 and Sting2 in a single command..

Please indicate your system, shell, input file naming convention, sample input file data, expected output and what you've tried so far.

As gary__w said, further details are required.
However, assuming you're in the directory where your text files are, I think you could use something like:

grep -l string1 * | grep string2 - | cut -d":" -f1

This will show you only those filenames which have both string1 and string2 on its content.
Good luck!

I am using AIX 7.1, Korn Shell and filename.txt

Try

egrep -l "string1|string2" *.txt

EDIT: Actually, do you want files with both strings in the same file, or files with either string? Your description seems a little ambiguous.

Single command may not be the most efficient. Try:

awk 'FNR==1{a=b=f=0}f{next}$0~s1{a=1}$0~s2{b=1} a && b{print FILENAME;f=1}' s1="String1" s2="String2" file*

Actually, in case 500 files are too many for a single command:

for i in file*; do
  awk 'FNR==1{a=b=f=0}f{next}$0~s1{a=1}$0~s2{b=1} a && b{print FILENAME;f=1}' s1="String1" s2="String2" "$i"
done