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

Linux

8280 readers
381 users here now

A community for everything relating to the GNU/Linux operating system (except the memes!)

Also, check out:

Original icon base courtesy of [email protected] and The GIMP

founded 2 years ago
MODERATORS
 

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
[–] [email protected] 0 points 4 weeks ago (1 children)

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

grep -o ‘/dev/loop[0-9]+’
[–] [email protected] 2 points 4 weeks ago (1 children)

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

[–] [email protected] 1 points 4 weeks ago

Also, your quotes are wrong, ‘ should be ’ .

Alright, I am getting confused. What quotes are those?

I got this from the stuff I copied from your comment:

❯ ./UTF8txt2hex ’‘
UTF-8: e2 80 99 e2 80 98
UTF-16: 2019 2018 
UCS 4: 00002019 00002018 

And these are the single quote and backtick I used (of course I had to escape them, because they are the actual ones):

❯ ./UTF8txt2hex \`
UTF-8: 60
UTF-16: 60 
UCS 4: 00000060 
❯ ./UTF8txt2hex \'
UTF-8: 27
UTF-16: 27 
UCS 4: 00000027 

And from what I see, your original comment had the correct ones, so was this all to elicit this response out of me?