while read LINE; do a=$(echo "$LINE" | cut -d';' -f 1); b=$(echo "$LINE"|cut -d';' -f 2); c=$(echo "$LINE"|cut -d';' -f 3); filename=$(echo "$b ($c).pdf"|iconv -f ISO_8859-1 -t utf-8); curl -Lo "$filename" $a; done < together.txt car=a; while read LINE; do a=$(echo "$LINE" | cut -d';' -f 1); b=$(echo "$LINE"|cut -d';' -f 2); c=$(echo "$LINE"|cut -d';' -f 3); filename=$(echo "$b ($c).pdf"|iconv -f ISO_8859-1 -t utf-8); if [ -e "$filename" ]; then var=$(echo $var | tr 'a-y' 'b-z'); filename=$(echo "$b ($c$var)); fi; wget -nc -O "$filename" $a; done < together.txt FINAL VERSION: car=a; while read LINE; do a=$(echo "$LINE" | cut -d';' -f 1); b=$(echo "$LINE"|cut -d';' -f 2); c=$(echo "$LINE"|cut -d';' -f 3); filename=$(echo "$b ($c).pdf"|iconv -f ISO_8859-1 -t utf-8); if [ -e "$filename" ]; then car=$(echo $car | tr 'a-y' 'b-z'); filename=$(echo "$b ($c$car).pdf" | iconv -f ISO_8859-1 -t utf-8); fi; wget -nc -O "$filename" $a; done < together.txt THE FFIINNAALL VERSION ☺: This code works assuming there're no PDFs in the current directory etc. and the together.txt file is alphabetically sorted by title: while read LINE; do a=$(echo "$LINE" | cut -d';' -f 1); b=$(echo "$LINE"|cut -d';' -f 2); c=$(echo "$LINE"|cut -d';' -f 3); filename=$(echo "$b ($c).pdf"|iconv -f ISO_8859-1 -t utf-8); if [ -e "$filename" ]; then car=$(echo $car | tr 'a-y' 'b-z'); filename=$(echo "$b ($c$car).pdf" | iconv -f ISO_8859-1 -t utf-8); else car=a; fi; curl -Lo "$filename" $a; done < together.txt