grep -o '/dev/loop[0-9]\+'
Why are you making a literal out of the + operator? This will not work.
grep -o โ/dev/loop[0-9]+โ
Because it does work, you need grep -E
for '+' to work without escaping. Also, your quotes are wrong, โ should be ' .
You could try [0-9] instead?
awk '/\/dev\/loop[0-9]/ {print}'
If you have a larger sample of input and desired output, people can help you better.
Assuming you made a bit of a typo with your regexp, any of these should work as you want:
grep -oE '/dev/loop[0-9]+'
awk 'match($0, /\/dev\/loop[0-9]+/) { print substr($0, RSTART, RLENGTH) }'
sed -r 's%.*(/dev/loop[0-9]+).*%\1%'
AWK one is a bit cursed as you can see. Such ways of manipulating text is not exactly it's strong suite.
I know this isn't grep or awk but of you simply want the first part I would probably use cut as following: ``` cut -d : -f 1
Simply put, cut the line in multiple parts with the colon as the delimiter and choose the first part.
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].
Linux
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