bash,正则表达式的grep问题

用户名

从给定的文件中,我只想检索具有“ rt_view_product”和“ user_id”的行

我的代码是:

cat some_file | grep '"(rt_view_product)(.*)(user_id)*"' >> view_event.log

我知道'some_file'具有这种类型的行,但是view_event.log仍然为空

我还在https://regex101.com/上检查了我的正则表达式,它似乎可以正常工作

这里是“ some_file”行的示例:

/v1/events?os=android&bundle=test&event=rt_view_product&network=Organic&ip=0.0.0.0&time=1437352628&country=th&device_name=TRUESMART4.0&os_version=19&session=12&adid=d963faa323b2cd971467d7ddd63b5125&google_play_advertising_id=d9676bba-b664-4d0b-be3d-94e542e0768c&language=th&tracking_enabled=1&time_spent=1618&environment=production&timezone=UTC%2B0700&sdk_version=android4.0.5&device=Phone&device_model=TRUE+SMART+4.0&display_size=3.88&app_version=3.0.12&device_manufacturer=alps&gender=Male&product=ODFLKGJDFLKGJ&shop_country=TH&user_id=7474774

理想情况下,我想保存:

7474774 (<= value of user_id),ODFLKGJDFLKGJ(<= value of product)
Nowox

您不需要使用括号:

$ echo "rt_view_product something user_id" > foo
$ grep 'rt_view_product.*user_id' foo
rt_view_product something user_id

https://regex101.com/r/sG0bW3/1

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章