Using a perl compatible regex with GNU grep -P

grepregular expression

I'm using this regex (?<=\[')[^,]* on a file containing the following line disk = ['OVS/sdasd/asdasd/asdasd/something.img, w']

I want that to return OVS/sdasd/asdasd/asdasd/something.img

How do I use grep to make it work?

I've tried grep -P "(?<=\[')[^,]*" but it returns the whole line.

Best Answer

Add the -o switch so that grep only returns what matches the pattern you're grepping for:

$ grep -Po "(?<=\[')[^,]*" data.txt 
OVS/sdasd/asdasd/asdasd/something.img
Related Question