Harish Srinivas bio photo

Harish Srinivas

“Autodidact with an insatiable thirst for learning something new everyday. Wearer of many hats. DevOp Engineer/Release Engineer, Security Engineer, Linux fanatic, Amateur photographer, Maker & Novice App developer.”

Email

At work today I had to run a lot of SQL files which had  --//@UNDO  followed by SQL commands to rollback the transactions  carried out at the top of the file. This is standard for SQL migration files, However MySQL server errors out when it encounters this. I used a quick shell script to remove all the --//@UNDO and all the SQL commands which followed it.

for i in *; do echo "Processing" $i; sed '/\-\-\/\/@UNDO/,$d' $i > /tmp/$i; done;

The above line will delete all lines starting from --//@UNDO until the end of file. The modified contents are then written to /tmp. The original file remains unchanged.