reading files from a directory.

Can some body help me to code this?

go to a specific directory.(/home/abcd/test)

file1.txt,
file2.txt,
...
..
filen.txt

read the files in side the folder 'test' and print the content of each file into other folder in the same directory lets say(testresult) with the same file name and .sql extension.

file1.sql(extension is .sql).
file2.sql
file3.sql
...
...
filen.sql

Example:

ls -1 *.txt | while read file; do cp $file testresult/${file%.*}.sql; done
find /home/abcd/test -type f | while read a
do
cat $a > "${a%/*}"/testresult"${a##*/}".sql
done

---------- Post updated at 04:29 PM ---------- Previous update was at 04:25 PM ----------

cd /home/abcd/test
ls *.txt | xargs -i cp {} ./testresult/{}.sql

Ooops i forgot to remove the .txt extension, go for cabrao solution then ! :smiley:

ls -l .txt | while read file; do awk '{if(NR==1)
{
t=$1;
$1=""
s="ALTER TABLE ADD COLUMN " t" "$0
next;
}
s=s" ,"$0
}
END {
print s" ) " }' $file*.
; done
awk: cmd. line:12: fatal: cannot open file `-rwxrwxrwx' for reading (No such file or directory)
awk: cmd. line:12: fatal: cannot open file `-rwxrwxrwx' for reading (No such file or directory)

i want to execute the awk command functionality during each file reading but it seems it does work for me ..any idea about the error?
Regards

for i in *.txt
do
  cp -p "$i" "testresult/${i%.*}.sql"
done