包含`“:”`模式的grep字符串

时间:2018-12-05 06:25:09

标签: bash grep

这是我服务器中日志文件的一部分

"order_items_subtotal":"60.5100","order_final_due_amount":"0.0000","items":[{"product_id"

我需要在整个日志文件中grep包含"order_final_due_amount":"0.0000"的日志。

为此,我确实喜欢

tail -f pp_create_shipment2018-12-05.log | grep "order_final_due_amount":"0.0000"

但是我得到零结果。我的tail命令怎么了

2 个答案:

答案 0 :(得分:4)

"由外壳程序解释(用于引用例如空格)。

grep "order_final_due_amount":"0.0000"

等同于

grep order_final_due_amount:0.0000

要将"传递给grep,您需要引用它:

grep '"order_final_due_amount":"0\.0000"'

(此外,.在正则表达式中很特殊,应该转义。)

答案 1 :(得分:0)

使用Perl,您只需要转义“”即可。单独。 qr //负责其余部分。 检查一下:

> cat product.log
order items
items1
"order_items_subtotal":"60.5100","order_final_due_amount":"0.0000","items":[{"product_id"
item2
"order_items_subtotal":"60.5100","order_final_due_amount":"000000","items":[{"product_id"
items3
"order_items_subtotal":"60.5100",order_final_due_amount:"0.0000","items":[{"product_id"
items4
>  perl -ne ' $pat=qr/"order_final_due_amount":"0\.0000"/; print if /$pat/ ' product.log
"order_items_subtotal":"60.5100","order_final_due_amount":"0.0000","items":[{"product_id"
>

感谢melpomene,以下内容也适用

> perl -ne ' print if /"order_final_due_amount":"0\.0000"/ ' product.log
"order_items_subtotal":"60.5100","order_final_due_amount":"0.0000","items":[{"product_id"
>
相关问题