我有php文件,SQL查询分为多行。 例如:
$sql = "select count( aa." . BOOK_ART_ID . ") as book_count
from " . BOOK_ART_TABLE . " as aa
inner join " . AUTHER_TABLE . " as l on aa." . BOOK_ART_AUTHER_ID . " = l." . AUTHER_ID . " AND
l." . AUTHER_CODE . " = '" . "'
where aa." . BOOK_ART_TITLE_ID . " = " . $book_id;
我正在尝试从PHP文件中提取所有SQL语句。我在$ sql上尝试grep并且只返回第一行。
如何从所有PHP文件中提取整个SQL字符串?
我正在考虑删除换行符,直到';'字符。
答案 0 :(得分:1)
您可以尝试此sed
,
sed -n '/\$sql/{ :loop; N; s/ *\n *//g; /;/{p;q}; t loop}' yourfile
<强>测试强>
$ sed -n '/\$sql/{ :loop; N; s/ *\n *//g; /;/{p;q}; t loop}' yourfile
$sql = "select count( aa." . BOOK_ART_ID . ") as book_countfrom " . BOOK_ART_TABLE . " as aainner join " . AUTHER_TABLE . " as l on aa." . BOOK_ART_AUTHER_ID . " = l." . AUTHER_ID . " ANDl." . AUTHER_CODE . " = '" . "'where aa." . BOOK_ART_TITLE_ID . " = " . $book_id;