Now, some grep implementations, starting with GNU grep added a -o option to print the matched portion of each line (what is matched by the regexp, not its capture groups). You have sed (the stream editor) or awk for that. It's not its role to edit the content of those lines. Its primary purpose is to print the lines that match a regexp. Grep's name comes after the g/re/p ed command. What I've tried to do is include another \K to ignore it as grep -Po ".zoo.\K(.*):\K (.*)$" fileīut that gave me only the second capture group as 0.556984.Īlso with a non-capturing group with the (?:) syntax as grep -Po ".zoo.\K(?=.someString:More-RandomString (string here too)):\ (.*)$"īut this gave me nothing. I know for a fact that I have a group (.*) that is capturing those words in the middle. But I am not able to skip the words/lines between two capturing groups. I am able to get the first number from the first capturing group as 2, and also to match a capturing group at the end of the line. I used a regEx grep -Po ".zoo.\K(.*):\ (.*)$" fileīut this is producing me a result as 2.someString:More-RandomString (string here too): 0.45654343 I want to capture the numbers 2 and 0.45654343 from the above line. ![]() The input file has lines containing strings like: FOO_1BAR.zoo.2.someString:More-RandomString (string here too): 0.45654343 ![]() I am using GNU grep with the -P PCRE Regex support for matching strings from a file.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |