Regex Pattern matching and extraction using grep

advertisements

I have very strange interest to pattern match a line for a string and extract a value using grep. Below is the input and I want to extract the date alone from the string.

Input Host-GOOGLE-production.2015-08-01-21.migrant.deploy:{R:[{A:"0b87654nuy",RC:"JAVA".....[and the line continues]

For the above input, I wanted to write a regex that matches the date and string that comes after {A:" and before ",RC:. I know I can do this through sed and awk but I wanted to perform this task only through grep.

As a first step, to extract only the data, I tried the below command but it dint work. Someone know how to extract both these strings to extract the values. please share your thoughts. It would be nice if I get an answers/suggestion that extract both values 2015-08-01 & 0b87654nuy in one single command using grep

$grep -o --perl-regexp "(Host-GOOGLE-production.([0-9]+?-[0-9]+?-[0-9]+)?-.*)"

Desired O/P for the above command: 2015-08-01


I wanted to write a regex that matches the date and string that comes after {A:" and before ",RC:

You can use this grep:

grep -oP '(?<=A:").*?(?=",RC:)' file
0b87654nuy