Thursday, May 2, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1085  / 2 Years ago, fri, august 19, 2022, 12:13:57

I have a simple shell script on my Ubuntu 13.10 Server to download all files in a list.



filen="/home/chester/test/workobject.txt"
dir_log="/home/chester/test"

if [ -f "$filen" ]
then
cd $dir_log
for n in `cat $filen`
do
echo $n
wget -O $n.txt -q http://domain.com/QuickSearch?object=$n&search=Overview
done
else
echo "Nothing to do."
fi


The contents of workobject.txt:



9957881
9A39879


The script works properly. However, when it downloads the 9957881.txt files, it changes the filename to 9Z44X7~P.txt instead.



What is wrong with the script?


More From » command-line

 Answers
5

I did a check on the output and it shows a %0D on the filename. Upon more research, I have found out that this is the trailing line break on the workobject.txt. Sadly, I cannot do anything about the formatting of workobject.txt file because it is only being pushed to my server via scp.



I just let the script do the same thing and just batch rename all the files after processing to remove the %0D trailing the filename.



So the final script looks like this:



filen="/home/chester/test/workobject.txt"
dir_log="/home/chester/test"

if [ -f "$filen" ]
then
cd $dir_log
for n in `cat $filen`
do
wget -q http://domain.com/QuickSearch?object=$n
done
else
echo "Nothing to do."
fi
rename "s/%0D//g" Quick*


Worked like a charm.


[#28148] Saturday, August 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
montwim

Total Points: 103
Total Questions: 112
Total Answers: 120

Location: Vietnam
Member since Mon, Mar 14, 2022
2 Years ago
montwim questions
;