I want to extract only the carrier part (u0026carrier=Jio%204G) from the below code:

/v1.6/32359233/init?os=android%20%3A%208.0.0%20%3A%20O%20%3A%20sdk%3D26\u0026model=SM-J810G\u0026carrier=Jio%204G\u0026ct=13\u0026bundle=io.teslatech.callbreak\u0026mcc=405870\u0026d=1.75\u0026screen=1280%2C720\u0026optout=0\u0026ts=1556672633159\u0026manufacturer=samsung\u0026locale=en\u0026di=5.383004822116628\u0026play_version=11400000\u0026admob_enabled=true\u0026facebook%20enabled=false\u0026mopub%20enabled=true\u0026unit_id=unit-3943\u0026unit_id=unit-3944\u0026unit_id=float-3335\u0026unit_id=float-3336\u0026unit_id=float-3339","method":"GET","version":"v1.6","prefix":"hit","hostname":"adxserver-7d6bcd74d8-5zxsn

The content for carrier varies in length. hence. I want to extract the data present between two backslash irrespective of the length.

1 Answers

0
Vijay On
perl -lne 'print $1 if(/.*?(\\u[^\\u]+carrier=[^\\u]+)\\u.*/)' your_file

Tested below:

$ cat temp
/v1.6/32359233/init?os=android%20%3A%208.0.0%20%3A%20O%20%3A%20sdk%3D26\u0026model=SM-J810G\u0026carrier=Jio%204G\u0026ct=13\u0026bundle=io.teslatech.callbreak\u0026mcc=405870\u0026d=1.75\u0026screen=1280%2C720\u0026optout=0\u0026ts=1556672633159\u0026manufacturer=samsung\u0026locale=en\u0026di=5.383004822116628\u0026play_version=11400000\u0026admob_enabled=true\u0026facebook%20enabled=false\u0026mopub%20enabled=true\u0026unit_id=unit-3943\u0026unit_id=unit-3944\u0026unit_id=float-3335\u0026unit_id=float-3336\u0026unit_id=float-3339","method":"GET","version":"v1.6","prefix":"hit","hostname":"adxserver-7d6bcd74d8-5zxsn

$ perl -lne 'print $1 if(/.*?(\\u[^\\u]+carrier=[^\\u]+)\\u.*/)' temp
\u0026carrier=Jio%204G
$