开发者

Convert string to xml in shell script?

I have written a script which is fetching data from database.

Now I want to enhance that script to create a xml file with data which is return by database.

How may i convert that string to xml file in shell script.

script.sh

#!/bin/sh
echo 'SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb" FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema="database_开发者_StackOverflow社区name";' | mysql -u root -pmysql

data getting from database

"Table Name\tQuant of Rows\tTotal Size Mb\ntable_1\t2\t0.02\ntable_2\t1\t0.02\ntable_3\t142\t0.02\ntable_4\t50839\t5.03\ntable_5\t16573\t5.13\ndlr\t0\t0.02\ntable_6\t6\t0.02\ntable_7\t0\t0.03\ntable_8\t2\t0.08\ntable_9\t4\t0.02\n"

I want to write some logic into script which convert this string to xml file.

How may i do that ? What are the preferred way to handle this scenario ?


Try something like this -

shell> mysql --xml -e "SELECT * FROM test.person" > person-dump.xml

--xml option produces XML-like output.

MySQL command-linel client ref.


#!/bin/sh
mysql -u root -pmysql --xml > /home/test/Desktop/temp.xml << eof
SELECT TABLE_NAME AS "Table Name", table_rows AS "Quant of Rows", ROUND((data_length + index_length)/1024/1024,2) AS "Total Size Mb"  FROM information_schema.TABLES WHERE information_schema.TABLES.table_schema='database_name';
eof
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜