How to get a value from a file and serach that value filename in a dir?

buddies,

my requirement would be as follows,

I have a file called test.txt and content of it would be

yahoo
gmail
hotmail

and i want to search a file name called "yahoo.html" (first line of test.txt) and then "gmail.html" and then "hotmail.html" in a /home/test dir.

Any idea to achive this ?

Hello natraj005,

Could you please try following and let me know if this helps you(I haven't tested though).

while read line
do
    find /home/test -type f -iname $line".html"
done < "test.txt"

Thanks,
R. Singh

RavinderSingh13,

to be more specfic i have to capture each line from test.txt and assign it to a variable called MAIL and then i can assign that to another variable

like below

PERSONAL_MAIL=/home/test/www.$MAIL.com

so PERSONAL_MAIL will have all three files names like below

/home/test/www.yahoo.com
/home/test/www.gmail.com
/home/test/www.hotmail.com

and then i will serach a patern called "username" in all the three files, like below

MAIL_INFO=$(grep "^username" $PERSONAL_MAIL

Hope am not confusing you :slight_smile:

dir=/home/test

while read MAIL
do
   PERSONAL_MAIL=$dir/www.$MAIL.com
   echo $PERSONAL_MAIL
done < test.txt

Thanks rdrtx1 for your quick reply!

what you gave is checking only in the first file i.e) only checking in /home/test/www.yahoo.com and coming out, and not checking in the remaining two files i.e) /home/test/www.gmail.com and /home/test/www.hotmail.com.

So, it has to search pattern "username" in all the file one by one till the test.txt gets empty or reach the bottom line of it.

Difficult to believe. When running rdrtx1's proposal, I get exactly the desired output. Does your input resemble the given sample data?

Am trying below script and it is not working

dir=/home/test

while read MAIL
do
   PERSONAL_MAIL=$dir/www.$MAIL.com
   ACCOUNT=$(grep -c mail $PERSONAL_MAIL)
   if [ -z "$PERSONAL_MAIL" ]
       then
            if [ -z "$ACCOUNT" ]
               echo "$PERSONAL_MAIL is avaiable "
       else
               echo "$PERSONAL_MAIL not avaiable "
       fi
    fi
   
done < test.txt

above script is not searching for all the line in test.txt and content of the file is as like below

yahoo
gmail
hotmail

let me know if i still confusing you....

Above script doesn't even run but errors out. If the syntax error has been corrected, there still remains a logical flaw (actually it occurs twice). Those corrected, it processes all three entries in your test file.

Thanks Rudic, as i informed in the other thread it is working for me now.

its worked for me.... both "for" and "while" worked for me, its my bad early i used it wrong.

Thanks guys for helping me!!!