I have a small need to import the contents of a text into a MySQL table. I'm not using load, I'm using insert to do the following:
Text content:
1 China 156 http:// data.10086.cn/fs/nmpfs/media/p/2/2/6/pubattachment/20160718/1261.jpg 2 American 840 http://data.10086.cn/fs/nmpfs/media/p/2/2/6/ pubattachment/20160718/1277.jpg 3 Japan 392 http://data.10086.cn/fs/nmpfs/media/p/2/2/6/pubAttachment/20160718/1278.jpg 4 Germany 280 http:// data.10086.cn/fs/nmpfs/media/p/2/2/6/pubattachment/20160718/1267.jpg 5 Russia 810 http://data.10086.cn/fs/nmpfs/media/p/2/2/6/pubattachment/ 20160718/1268.jpg 6 UK 826 http://data.10086.cn/fs/nmpfs/Media/p/2/2/6/pubattachment/20160718/1286.jpg
The
uses awk to turn into an INSERT statement:
cat b.txt |awk ' {print ' insert into all_countries values ("$", \047 "$ "\047,\047" $ "\047,\047" $4 "\047); insert into all_countries values (1, ' China ', ' 156 ', ' http://data.10086.cn/fs/nmpfs/media/p/2/2/ 6/pubattachment/20160718/1261.jpg ');insert into all_countries values (2, ' Us ', ' 840 ', ' http:/ /data.10086.cn/fs/nmpfs/media/p/2/2/6/pubattachment/20160718/1277.jpg '); insert into all_countries values (3, ' Japan ', ' 392 ', ' http://data.10086.cn/fs/nmpfs/media/p/2/2/6/pubAttachment/20160718/1278.jpg ') ;insert into all_countries values (4, ' Germany ', ' 280 ', ' HTTP://DATA.10086.CN/FS/NMPFS/MEDIA/P/2/2 /6/pubattachment/20160718/1267.jpg ');insert into all_countries values (5, ' Russia ', ' 810 ', ' http ://data.10086.cn/fs/nmpfs/media/p/2/2/6/pubattachment/20160718/1268.jpg '); insert into all_countries values (6, ' UK ', ' 826 ', ' Http://data.10086.cn/fs/nmpfs/media/p/2/2/6/pubAttachmeNt/20160718/1286.jpg ');
This article is from the "just out of the shell of the Birds" blog, please be sure to keep this source http://qhd2004.blog.51cto.com/629417/1831664
Awk escapes single quotes in English