문제

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