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 )
Not sure if I’m understanding, but can’t you just pipe the whole thing to
awk
and capture the first field? Likeecho "/dev/loop0: [2081]:64 (/a/path/to/afile.dat)" | awk -F: '{print $1}'
Which would print
/dev/loop0
That would also print the colon
No, because we’re telling to use
:
as a separator with the -F flagThe field separator is declared to be the colon, with -F:, so the fields end and start at colons.
Why would it print the colon?