Hi @sundar !
Hope this will get you started.
If you make a file called list.txt
like this:
tp1.nrrd
tp2.nrrd
tp3.nrrd
tp4.nrrd
Then running the script below like this ./loopOverFileLines.sh list.txt
will produce the output:
register tp2.nrrd to tp1.nrrd
register tp3.nrrd to tp2.nrrd
register tp4.nrrd to tp3.nrrd
I’ve left some work for you to do, because from our talk offline, I think you can fill
in what’s missing. But please ask questions if something is unclear.
John
loopOverFileLines.sh
#!/bin/bash
# the input to this script should be a text file, with the path to a file on each line, in order
# Make sure there's exactly one input
if [[ "$#" -ne 1 ]]; then
echo "Must provide a file" >&2
exit 1
fi
list="$1"
i="0"
current=""
previous=""
for t in `cat $list`
do
previous="$current"
current="$t"
# do nothing when $i equals zero, since we work on pairs.
if (( $i > 0 ));
then
# In here, the "$current" variable stores whatever is on line (i) of the input
# the "$previous" variable stores whatever is on line (i-1) of the input
echo "register $current to $previous"
# PUT
# YOUR
# COMMANDS
# HERE
fi
((i++))
done