14
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
[-] 4am@lemm.ee 1 points 1 week ago

Why are you making a literal out of the + operator? This will not work.

grep -o โ€˜/dev/loop[0-9]+โ€™
[-] pelya@lemmy.world 3 points 1 week ago

Because it does work, you need grep -E for '+' to work without escaping. Also, your quotes are wrong, โ€˜ should be ' .

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

Linux

7932 readers
545 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