My sample line looks like this:
This is 02G05 a test string 20-Jul-2012
Now from this line I want to extract 02G05 . For this, I tried the following regex with sed
$ echo "This is 02G05 a test string 20-Jul-2012" | sed -n '/\d+G\d+/p'
But the above command does not print anything, and I believe that it cannot match anything with the pattern that I passed sed.
So my question is what I'm doing wrong here and how to fix it.
When I try to use the above string and pattern with python, I get my result
>>> re.findall(r'\d+G\d+',st) ['02G05'] >>>
bash regex sed
RanRag Jul 19 '12 at 20:34 2012-07-19 20:34
source share