by sshine · 8y ago · 0 comments
grep -Po '(?<=...)pattern'
Which also cuts out and prints the relevant part of the line. This saves a trip through cut, awk or perl. (-P is PCRE and -o is print only matched characters, which the lookarounds aren't a part of.) $ echo 'foo=5, Bar=3; x1=83, y=120' | grep -oP '\b[a-z]+=\K\d+'
5
120
further reading: https://stackoverflow.com/questions/11640447/variable-length... grep -oP '(?<=...)pattern(?=...)'
The caveat however is that the look{ahead,behind} pattern has to be of fixed length.You've made my day.