Ubuntu 16 Bash strange output

Hello,

I work in Ubuntu 16.04, I am new to Bash and something is wrong with my script, please help.

I have a few hundreds of subjects data (like subj003.nii.gz, subj012.nii.gz etc. up to subj567.nii.gz) in a directory /usr/afewmoredirectories/subjects.

I may run for each subject a command like

recon-all -subject subj003 -i subj003.nii.gz -all

which runs without error.

Instead I try to automatize the process. So I create two files:

In the list.txt I have a column of all the subject id (like subj003, subj012 etc. up to subj567)
In the doit.sh I have 2 lines:

name=$1
recon-all -subject ${name} -i ${name}.nii.gz -all

Then I execute in the root terminal

cat list.txt | xargs -I @ -P 3 ./doit.sh @

and something is wrong because instead of running the commands the output is:

.nii.gzcannot find subj012

Could you please explain me what I is wrong?

Without digging deeper, I suspect the list file to have DOS line terminators <CR> (aka \r, 0x0D, ^M). Remove those and retry.

1 Like

Thank you.
I tried

grep -URl ^M . | xargs fromdos
xargs: fromdos: No such file or directory

and

 grep -URl $'\r' . | xargs fromdos
xargs: fromdos: No such file or directory

Do you have any other suggestions?

Hello lim-lim,

You should use Input_file name with grep command, like as follows.

grep "test_test" Input_file

Thanks,
R. Singh

What be the output of either grep command?
Does fromdos run from the command line?

You were right however. It was CR line terminators, I just did not check that properly.

Fromdos and dos2unix did not help, dunno why, but what helped was

vim list.txt +"%s/\r/\r/g" +wq

Then everything worked