Could you please add more details on your statement where the first column is a substring of the string of file.
What is the rule to fetch the substring? Is it first n characters or first 2 words?
Also please clarify on phrase each file contain a string .
So, is "My name is Mark and I'm a child" the sole content of the file? Does each file contain only one line?
DIR=/directory/with/2000/files
for FILE in $(ls $DIR)
do
echo "insert into tabella ('"$(awk '{print substr($0,1,7)}' $DIR/$FILE)"','"$(cat $DIR/$FILE)"');"
done
Beware of ' appearing within fields for inserts to be successful.
Change only the directory name assigned to variable DIR. Leave the remaining as is. substr should be on the line and hence $0 for awk to read the line.
./prova.sh[6]: awk{print substr($0,1,7)}: not found
this is the script:
#!/usr/bin/ksh
DIR=/home/oracle/prova/manu
for FILE in $(ls $DIR)
do
echo "insert into comments('"$(awk'{print substr($0,1,7)}' $DIR/$FILE)"','"$(cat $DIR/$FILE)"');" >> prova.txt
done
$ echo "My name is Mark and I'm a child" | awk '{print "insert into tabella (""\x27"substr($0,1,7)"\x27","\x27"$0"\x27"")"}' OFS=,
insert into tabella ('My name','My name is Mark and I'm a child')