Insert into mysql DB from text files

6 Mar 2010

by hemanth

  1. #!/bin/bash
  2. #==================================================================
  3. #
  4. # FILE: insertDb.sh
  5. #
  6. # USAGE: ./insert.sh
  7. #
  8. # DESCRIPTION: Illustration of inserted data from text to DB
  9. #
  10. # OPTIONS: ---
  11. # REQUIREMENTS: ---
  12. # BUGS: ---
  13. # NOTES: ---
  14. # AUTHOR: Hemanth H.M (), hemanth.hm@gmail.com
  15. # VERSION: 1.0
  16. # CREATED: 03/06/2010 12:30:36 AM IST
  17. # REVISION: ---
  18. #=================================================================#
  19. #Example scenario assume a list with words and meanings with space #as IFS, or you have two files with words in one of them and #menaings in the other.
  20. #sed -e 's/ /#/' list | awk -F "#" '{print $1}' > words
  21. #sed -e 's/ /#/' list | awk -F "#" '{print $2}' > means
  22.  
  23. while read f1 <&7
  24. do
  25. read f2 <&8
  26. mysql -uroot -proot dict <<< "insert into words values ('$f1','$f2');"
  27. # dict is the table
  28.  
  29. done \
  30. 7<words \
  31. 8<means
Share this