In a (BSD) UNIX environment, I would like to capture a specific substring using a regular expression.
Assume that the dmesg
command output would include the following line:
pass2: <Marvell Console 1.01> Removable Processor SCSI device
I would like to capture the text between the <
and >
characters, like
dmesg | <sed command>
should output:
Marvell Console 1.01
However, it should not output anything if the regex does not match. Many solutions including sed -e 's/$regex/\1/
will output the whole input if no match is found, which is not what i want.
The corresponding regexp could be:
regex="^pass2\: \<(.*)\>"
How would i properly do a regex match using sed
or grep
? Note that the grep -P
option is unavailable in my BSD UNIX distribution. The sed -E
option is available, however.
camcontrol devlist
than the output ofdmesg
.