Adding line in a file using info from previous line

I have a shell script that looks something like the following:

mysql -uroot db1 < db1.sql
mysql -uroot db2 < db2.sql
mysql -uroot db3 < db3.sql
mysql -uroot db4 < db4.sql
....

different db names in more than 160 lines.
I want to run this script with nohup and have a status later.
So, basically, I need a quick fix to insert another line after each restore command above that says the database is restored.

mysql -uroot db1 < db1.sql
echo db1 is restored
mysql -uroot db2 < db2.sql
echo db2 is restored
mysql -uroot db3 < db3.sql
echo db3 is restored
mysql -uroot db4 < db4.sql
echo db4 is restored
....

How can this be done with vi and unix utilities?
Thanks in advance,
-MKH

Any attempts from your side?

I can make all sorts of modifications/additions on the same line. My challenge is adding the new line. I created the script using

ls -l | awk '{print $9}' > restore.sh

and then using different vi/awk commands to modify the lines into single mysql restore lines.
I ran the script overnight, but was looking for ways to report the status of the restore.

perl -lne 'print; print "echo $1 is restored" if /(db\d+)\.sql$/' db.script > new_db.script

First: note that:

ls -l | awk '{print $9}' > restore.sh

could be much more simply and correctly written as:

ls > restore.sh

A simple way to see the progress of a script is to trace it while it runs. I.e., instead of running your script with:

sh restore.sh

run it with:

sh -x restore.sh

With your current script, adding the echo statements can easily be done with:

awk '{print;printf("echo %s is restored\n", $3)}' restore.sh

And, starting from scratch, if I understand what you're trying to do, the following should come close to automatic creation of your script:

#!/bin/ksh
for dbs in *.sql
do      db="${dbs%.sql}"
        printf 'mysql -uroot %s < %s\necho %s is restored\n' "$db" "$dbs" "$db"
done > restore.sh

Looks like you didn't know that you can put two commands on the same line, separated by a semicolon. With this trick you might have been able to manage it yourself.

mysql -uroot db1 < db1.sql; echo db1 is restored

Important note: simply echo-ing that something happend - especially like you intend to do here - is not something you can really rely on, thus I suggest following solution:

mysql -uroot db1 < db1.sql && echo "db1 is restored" || echo "db1 restore failed"

Otherwise your report will say that the db was restored even if the restore failed, for whatever the reason.

Thanks for the great pointers everyone!