You are not logged in.
Hi there,
Usually, when I want to filter strings with following pattern:
a substring 'I/O error' is in front of another substring with pattern 'sector a int here'
a few substrings are between 'I/O error' and 'sector'
Usually, I use two piped grep:
grep 'I/O error' /path/to/file | grep -E 'sector\s[[:digit:]]+'But I want to know if I can do it within one regex expression with 'grep -P'.
I tried
grep -P '(?<=I/O\serror.+)sector\s\d+' /path/to/file but it got an error
grep: lookbehind assertion is not fixed length So is it possible to do is using only one regex expression?
Offline
You can simply combine them:
grep -E 'I/O error.+sector\s[[:digit:]]+'Or with PCRE to exclude the first part from the match:
grep -P 'I/O error.+\Ksector\s[[:digit:]]+'Offline
You can simply combine them:
grep -E 'I/O error.+sector\s[[:digit:]]+'Or with PCRE to exclude the first part from the match:
grep -P 'I/O error.+\Ksector\s[[:digit:]]+'
Thanks for your reply, but the problem is that it will match the 'I/O error', I want some expression that only match 'sector\s[[:digit:]]' so I won't get useless message if I use '-Po'
Offline
The second one should do that? That \K escape sequence is actually mentioned in the pcrepattern man page as a way to get around the fixed-length restriction of lookbehind assertions.
Offline
The second one should do that? That \K escape sequence is actually mentioned in the pcrepattern man page as a way to get around the fixed-length restriction of lookbehind assertions.
It works, thank you.
Offline