I am trying to extract a string from the output of a DICOM directory
parser. The string I'm trying to match looks similar to this:
(0004,1500) CS #36 [DICOM\ST000000\SE000000\CR000000.DCM] Referenced File ID
"s" is a much larger string in which the target string is embedded.
From the console, this command produces no matches:
echo $s|egrep -o " \(0004,1500\) CS #[0-9]{2} \[.{,50}\] Referenced File ID "
However, any of these produce the expected result:
echo $s|egrep -o " \(0004,1500\) CS #[0-9]{2} \[.{,50}\] Reference. File ID "
echo $s|egrep -o " \(0004,1500\) CS #[0-9]{2} \[.{,50}\] Reference[d] File ID "
echo $s|egrep -o " \(0004,1500\) CS #[0-9]{2} \[.{1,50}\] Referenced File ID "
A typical output:
(0004,1500) CS #36 [DICOM\ST000000\SE000000\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000000\SE000000\CR000001.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000000\SE000001\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000000\SE000002\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000000\SE000003\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000000\SE000004\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000000\SE000005\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000001\SE000000\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000001\SE000001\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000001\SE000002\CR000001.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000001\SE000002\CR000000.DCM] Referenced File ID
(0004,1500) CS #36 [DICOM\ST000001\SE000003\CR000000.DCM] Referenced File ID
In summary, if I use the form, ".{,40}" to specify the variable part of
the string, egrep won't recognize a match between "Referenced" and
"Referenced", but will recognize "Reference." and "Reference[d]". If I
use ".{1,40}", then "Referenced" matches "Referenced", as expected.
This would seem to be a bug, unless there is something about the regular
expression that I'm missing.
I'm using GNU bash, version 4.1.5(1), and GNU grep, version 2.5.4
OS: Ubuntu 10.04.4 LTS
Any advice would be appreciated.
manthony121
Bookmarks