cross-posted from: https://programming.dev/post/31833654
Hi,
I would like to found a regex match in a stdout
stdout
/dev/loop0: [2081]:64 (/a/path/to/afile.dat)
I would like to match
/dev\/loop\d/
and return
/dev/loop0
but the
\d
seem not working with awk … ?How to achieve this ? ( awk is not mandatory )
You must log in or register to comment.
Regex syntax and features vary between implementations.
\d
isn’t supported by BRE/ERE flavors.GNU grep
supports PCRE, so you can usegrep -oP '/dev/loop\d'
orgrep -o '/dev/loop[0-9]'
if you are matching only one digit character.Use [0-9] to match the number
Or, alternatively,
[[:digit:]]
, and dont’ forget to add a quntifier+
to match multiple digits. See documentaion for details.awk '/^\/dev\/loop[[:digit:]]+/{print}'