質問

How can I output result into existing html template, using MySQL & Bash.

If I Write:

mysql --host="${VARS[6]}" --database="${VARS[9]}" --user="${VARS[7]}" \
      --password="${VARS[8]}" --execute="SELECT 1 FROM table_name" \
      --html --skip-column-names > $FILE

I get the result

<TABLE BORDER=1><TR><TR><TD>1</TD></TR></TABLE>

I want to get

<TABLE><TR><TR><TD>1</TD></TR></TABLE>

How can I re-declare a template so that MySQL is the output?

役に立ちましたか?

解決

You can use "--xml" option to MySQL and then transform the resulting XML output into either HTML or some other form of XML with XSLT.

Otherwise, if you don't need to retrieve data containing whitespace from MySQL, you can parse "mysql -ss" output and generate HTML in Bash.

Like this:

mysql -ss your_mysql_option... |
    while read col1 col2 col3; do
        echo "
            <TR>
                <TD>$col1</TD>
                <TD>$col2</TD>
                <TD>$col3</TD>
            </TR>
        "
    done
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top