我想减少 Mod_sec ID 的配额之间的数字:[id "31231"]。一般来说,这并不困难,但是当我尝试从多个报告中提取所有 ID 时,例如:
[Wed Oct 19 15:31:33.460342 2016] [:error] [pid 16526] [client 67.22.202.121] ModSecurity: Access denied with code 400 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/usr/local/apache/conf/includes/mod_security2.conf"] [line "4968"] [id "000784"] [hostname "example.org"] [uri "/"] [unique_id "WAfYJU1ol@MAAECO@HQAAAAI"]
[Wed Mar 19 15:31:33.460342 2016] [:error] [pid 16526] [client 67.22.202.121] ModSecurity: Access denied with code 400 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/usr/local/apache/conf/includes/mod_security2.conf"] [line "4968"] [id "9"] [hostname "example.org"] [uri "/"] [unique_id "WAfYJU1ol@MAAECO@HQAAAAI"]
[Wed Mar 19 15:31:33.460342 2016] [:error] [pid 16526] [client 67.22.202.121] ModSecurity: Access denied with code 400 (phase 2). Operator EQ matched 0 at REQUEST_HEADERS. [file "/usr/local/apache/conf/includes/mod_security2.conf"] [line "4968"] [id "00263"] [hostname "example.org"] [uri "/"] [unique_id "WAfYJU1ol@MAAECO@HQAAAAI"]
我尝试了几个命令,例如:
cat asd | awk '/\[id\ "/,/"]/{print}'
cat asd | sed -n '/[id "/,/"]/p'
和许多其他的,但它们不打印所需的 ID,而是包含额外的输出,因为模式被匹配了多次。一般来说,我可以做类似的事情:
cat asd | egrep -o "\"[0-9][0-9][0-9][0-9][0-9][0-9]\""
然后再次切断输出,但这在 ID 不包含 6 个数字的情况下不起作用。
我不熟悉 awk、sed 和 egrep 的所有选项,似乎没有找到解决方案。
我想从上面的历史中打印的是:
000784
9
00263
有人可以帮忙吗。先感谢您。