hello? The directory structure is as follows.
/image03
/UM1234ABCD2R1_MRI
/UM1234ABCD1R1_MRI
/UM0120AABD1R1_DTI
/UM0120AABC1R1_bold_reward
/CU0112XCMF2R1_b0map_bold
/CU1243XMDM1R1_b0map_dti
.....
There are hundreds of such directories, and among each of these directories, we want to output the following sentence only for directories that do not containing 'b0map'.
dcm2bids -d (directory name) -p (first 6 letters of directory) -S (10th letter of directory) -c /image03/dcm2bids_config.json
To this end, I wrote and ran a shell script like this, but an error came up. Could you please tell me how to solve it?
#!/bin/bash
DICOM_DIR = /image03/*/
PARTICIPANT_ID = {DICOM_DIR:0:6}
SESSION_ID = {DICOM_DIR:10}
for /image03/*$PARTICIPANT_ID*[^b0map]*/
do echo dcm2bids -d $DICOM_DIR -p $PARTICIPANT_ID -S $SESSION_ID -c /image03/dcm2bids_config.json
done
Error message
(EMBARC) [drbong@node16 EMBARC]$ ./anatfuncdti
./anatfuncdti: line 3: DICOM_DIR: command not found
./anatfuncdti: line 4: PARTICIPANT_ID: command not found
./anatfuncdti: line 5: SESSION_ID: command not found
./anatfuncdti: line 9: `/image03/*$PARTICIPANT_ID*[^b0map]*/': not a valid identifier
Thank you for your help while you are busy.
CodePudding user response:
this is bash... no space between your variable name and the value
more like:
DICOM_DIR='/image03/*/'
CodePudding user response:
suggesting the following:
find . -type d -not -name "*b0map*" | awk '{printf("dcm2bids -d %s -p %s -S -c /image03/dcm2bids_config.json\n", $0, substr($0,1,6), substr($0,10,1));}'
CodePudding user response:
find /image03 -type d -print0 |
{m,g}awk '($!NF=sprintf("%s -d %-35s -p %.6s -S %.1s -c /%s/%s_config.json;",
_="dcm2bids",$ _,$NF, substr($NF,10), $(NF-1), _))^(/b0map/)' \
RS='\0' FS='[/]'
———————————————————————————
dcm2bids -d /image03/UM1234ABCD2R1_MRI -p UM1234 -S D -c /image03/dcm2bids_config.json;
dcm2bids -d /image03/UM1234ABCD1R1_MRI -p UM1234 -S D -c /image03/dcm2bids_config.json;
dcm2bids -d /image03/UM0120AABD1R1_DTI -p UM0120 -S D -c /image03/dcm2bids_config.json;
dcm2bids -d /image03/UM0120AABC1R1_bold_reward -p UM0120 -S C -c /image03/dcm2bids_config.json;