简体   繁体   中英

Rename several files using its metadata content

I want to rename several files using a field in the metadata (patient names in DICOM files).

For example:

A001.dcm --> 1816.dcm

I found a utility called dcmdump:

dcmdump --search PatientName A001.dcm

Will output:

(0010,0010) PN [TEACHINGFILE-MG-1816] # 20, 1 PatientName

But I want to extract the "1816" part to use it to rename the file, so I tested

dcmdump --search PatientName A001.dcm | grep -E "MG\-(.*?)\]" -o

That gave:

MG-1816]

I would like to know how can I get just the "1816" part, and use it to rename the A001.dcm file.

Thanks in advance!!

You can use grep -P (PCRE) :

grep -oP "MG-\K[0-9]+"

OR sed:

sed 's/^.*MG-\([0-9]*\).*/\1/'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM