我有一个关于将linux命令输出(tshark)直接重定向到MySQL数据库的问题。
Tshark输出看起来像:
item-1:item-2:item-3:...:item-8
是否有任何非常简单而美观的方法将此输出直接重定向到MYSQL表中,行“item-1”...“item-N”?
任何样本对我都非常有用:)
答案 0 :(得分:0)
tshark-command|awk 'BEGIN {FS=":"};{print "insert into tbl_name (field1, field2, ..., field8) values (" $1 "," $2 "," $3 "," $4 "," $5 "," $6 "," $7 "," $8 ");"}' > insertcmd.sql
或者:
tshark-command|sed 's/^/insert into tbl_name \(field1,field2,...,field8\) values \(/g'|sed 's/:/,/g'|sed 's/$/);"
最后:
mysql dbname < insertcmd.sql
我没有对此进行过测试,但它应该有效。