find a string in a loop

Hi,

Can anyone help with the problem below? I need to read all text files (file1, file2, file3) in a loop and find

file1.txt:

file2.txt:

File3.txt:

Have you tried grep?

Could someone give me an example ?

var1 = /lpath1/lpath2/lpath3/lpath4/lpath5/

var2 = file1.txt

grep "$var1" file1 file2 file3

Each file (file1, file2, file3, file4) can have different entries. Also file can be empty

file1.txt:

file2.txt:

file3.txt :

file4.txt:

that doesn't matter...
what do you mean by find?? grepping that path from those files right??

We can have many text files (empty or with paths/files). I need to read each one and get var1 = path and var2 = filename.txt (if any) for the next ftp process.

if you need to parse all the lines in the text files, and you don't actually need to know which line came from which file, you can simplify your life a bit more. The cat utility will skip empty files without any problems.

cat *.txt | while IFS= read line
do
var1=${line%/*}
var2=${line#$var1/}
done