update mysql column with bash

270
August 21, 2017, at 10:56 AM

This is the code I got so far:

i=1
inputfile="data.txt"
    cat $inputfile | while read the_data; do
        while [ $i -le 100 ]; do
            echo "UPDATE table SET row=\"$the_data\" WHERE ID=$i;"
            i=$(( $i+1 ))
        done
    done | mysql -u root -pMY_PASS db_name;

This code partially works, but the problem is that the first line in data.txt is inserted into each row instead of new data lines into the right one.

Any ideas?

Answer 1

Duh, fixed it:

i=1
inputfile="data.txt"
    cat $inputfile | while read the_data; do
            echo "UPDATE table SET row=\"$the_data\" WHERE ID=$i;"
            i=$(( $i+1 ))
    done | mysql -u root -pMY_PASS db_name;

:-)

Rent Charter Buses Company
READ ALSO
Sql multiple keywords search

Sql multiple keywords search

Hello I am using mysql and I just learned there is no INTERSECT

254
Doctrine generating wrong INSERT statement

Doctrine generating wrong INSERT statement

I generated a MySQL database using Doctrine with Symfony and had to modify one table, by extracting two of its attributes and assign them to a new EntityThe first entity is called "Area" and the second one is called "Formato"

330