15
regex and awk... (programming.dev)

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 are viewing a single comment's thread
view the rest of the comments
[-] sxan@midwest.social 1 points 1 week ago

You've got lots of answers, so I'll just say that shorthand character classes like \s, \w, and \d - all those backslash ones - are not widely supported, especially in the only POSIX tools. Many tools have an extended or Perl mode that makes them available, but some don't. You can't rely on them being everywhere. That's why you're getting suggestions to use explicit, long-form character classes like [0-9].

this post was submitted on 08 Jun 2025
15 points (100.0% liked)

Linux

7897 readers
555 users here now

A community for everything relating to the GNU/Linux operating system

Also check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS