Issue
From a given file I only want to retrieve lines having 'rt_view_product' then whatever then 'user_id'
My code is:
cat some_file | grep '"(rt_view_product)(.*)(user_id)*"' >> view_event.log
I know that 'some_file' has this kind of line but view_event.log remains empty
I also check my regex on https://regex101.com/ and it seems to work fine
here an example of a line of '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
and idealy i would like to save:
7474774 (<= value of user_id),ODFLKGJDFLKGJ(<= value of product)
Solution
You don't need to use parenthesis:
$ 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
Answered By - nowox