I'm having a lot of trouble at work trying to save a long list of echo outputs as a .txt file on my desktop. I am using Bash in Yosemite 10.10.4. I am still very new to Bash so any help and tips are appreciated.
The goal is to print the name of the protocol used per brain scan, for a long list of brain scans. I used a for loop to recursively go through each brain scan, pull out the protocol used, then echo it and the path to the exact file used to acquire that information.
My script:
for i in /Path/to/scans/
do
for file in "$i/"001*/0001.dcm
do
# If there is no such file here, just skip this scan.
if [ ! -f "$file" ]
then
echo "Skipping $i, no 0001.dcm file here" >&2
continue
fi
# Otherwise take the protocol data from scan out
line= dcmdump +P 0040,0254 0001.dcm
## dcmdump is the command line tool needed to pull out this data.
## In my case I am saving to variable "line" the protocol used in
## the scan that this single 0001.dcm file belongs to (scans require
## many .dcm files but each one contains this kind of meta-data).
# Print the result
echo "$line $file"
break
done
done
So this script almost works. In my Terminal window, I do get a long list of protocols used, and the absolute filepath to the 0001.dcm file used for each scan.
My problem is, when I change it to
echo "$line $file" >> /Users/me/Desktop/scanparametersoutput.txt
The text file that appears on my desktop is blank. Anyone have any idea about what I am doing wrong?