Search a string in a file which is also present in another file in UNIX

Hi there,

I am new to Unix and had below requirement to finish my task.

I have file1.dat which has data as shown below.

case1.txt
case2.txt
case3.txt
case4.txt

file1.dat has only file names

I have folder which has above files mentioned in file1.dat

./all_files
case1.txt
case2.txt
case3.txt
case4.txt

data in case1.txt, case2.txt, case3.txt:

step1
step2
step3
step4

Now, I have to take particular step say step2 from each file, which is also present in file1.dat

Note: step2 is not line no:2 always.

Is this homework and if no, what have you tried?

Hi zaxxon,

thanks for your tips on formatting.

I didn't tried as i am new to unix.

I am just familiar with the commands, but not the scripting.

Thanks for understanding.

Unfortunately, you don't mention the shell you use. With e.g. bash , try

grep step2 $(<file1.dat)

.

sorry RudiC, forgot to mention yes its bash shell.

file1.dat has only file names.

where as the files(case1.txt, case2.txt, case3.txt) exists in ./all_files folder
lets say file1.dat is also in same folder

ex: the step2 in case1.txt should display if the file name 'case1.txt' is present in file1.dat

Please help

What's the result of the proposal in post#4 if run in directory all_files ?

the expected result will be..

step2 from all files (case1.txt, case2.txt, case3.txt), because the name(case1.txt, case2.txt, case3.txt) exists in file1.dat