【发布时间】:2016-06-23 04:03:35
【问题描述】:
我的脚本中有一个类似这样的命令
MESSAGE=`grep -Po 'MSG.\K[\w\s,.'\'',.:]*' < $FILENAME`
现在当这个命令运行时,我的输出看起来像这样
Kohl's EDI will be down for scheduled maintenance starting at 12:30 am until
approximately 4:00 am central time on Wednesday June 22nd. Kohl's will not be
able to send or receive EDI or AS2 transmissions during this time. If your
company's AS2 software has an automated process to resend a file after a
failure, Kohl's encourages your company to enable the resend process. This is
also a reminder for AS2 trading partners that Kohl's AS2 certificate will be
changing at 11:00 am central time on Tuesday June 21st.
现在在 grep 之后,我会将命令的结果传递给将要使用的变量,以便我可以将结果存储到 mysql 数据库中
问题是我该怎么做?
【问题讨论】:
-
$LINE包含文件的名称,或者您要在其中 grep 的数据? -
是的 @anishsane 它包含我想要 grep 的文件的名称
-
那么你的机制是正确的。您面临什么问题?
-
@anishsane 我在将它插入数据库时遇到了问题。我认为它不会插入到数据库中,因为我存储在变量中的是多行。如何将结果存储在一个变量中,以便将其插入数据库
-
好的,那么你的问题是 "如何在 mysql 数据库中插入多行数据",而不是 "如果结果有,我如何将 grepped 结果存储到变量中多行?”;因为你正确地做后者。