unix script with SQL statement problem

Hello,

I have a script to get the information from database, however, it's look like the loop is not work, can someone help? :confused:

echo Input file list to check:
read filelist
for file in 'cat $filelist.txt'
do
echo "select FILENAME from FILE_TABLE where filename like '${file}'%;" >> output_file.txt
done
echo Completed Check!!

The filelist is:
list1
A1-67630403
A2-04985959
B3-04857858
B6-058744748
C10-59584583

Single-quotes is the problem here. It should be backticks, like this:

for file in `cat $filelist.txt`

This method is not so good owing to useless use of cat. You can try the below method:

while read file
do
...
done < ${filelist}.txt

Also, I'm no expert at SQL, but shouldn't the echo statement be like this? (% with-in the single quotes)

echo "select FILENAME from FILE_TABLE where filename like '${file}%';"

sorry about the typing mistake, the % should be removed, like this

echo "select FILENAME from FILE_TABLE where filename like '${file}';"

Also, I used backticks in unix, still not work :frowning:

Please post the script you used.

I am tried to use your suggested while, is not work :eek:

What does not work? Do you see an errormessage or do you get wrong results? What shell, OS and database-system are you using?
About the SQL-syntax: its either filename = \'${file}\' looking for exact matches or filename like \'${file}%\' looking for values that start with those strings.

@happyv: We won't be able to help unless you provide more inputs.

I am just tried to use my original script and based on your comment,

echo Input file list to check:
read filelist
for file in `cat $filelist.txt`
do
echo "select FILENAME from FILE_TABLE where filename like '${file}'%;" >> output_file.txt
done
echo Completed Check!!

The filelist is:
list1
A1-67630403
A2-04985959
B3-04857858
B6-058744748
C10-59584583

the output will be:

FILENAME
____________________________________________________________________________________________________________________________________
ORIGMODIFYDATE
_________________
A1-67630403
20120317-18:09:52

FILENAME
____________________________________________________________________________________________________________________________________
ORIGMODIFYDATE
_________________
A2-04985959
20120315-20:09:52

Is it possible to make the output look better? e.g file and time on the same link?

Your select-statment only fetches the column FILENAME, not ORIGMODIFYDATE...
To answer your question we need to know what database system, and maybe what tool (SQL-client) you use to retrive the data. Your script creates some statments but does not issue them against the db.

all, it work now.