Bash, wget remove comma from output filename
I read the url file line by line, then pass the url to wget:
FILE=/home/img-url.txt
while read line; do
url=$line
wget -N -P /home/img/ $url
done < $FILE
This works, but some file contains a comma in the filename. How to save a file without comma?
Example:
http://xy.com/0005.jpg -> saved as 0005.jpg
http://xy.com/0022,22.jpg -> save as 002222.jpg not as 0022,22
I hope you find my question interesting.
UPDATE:
We have a good solution, but is there any solution to the stamping time error?
WARNING: timestamping does nothing in combination with -O. See the manual
for details.
source to share
This should work:
url="$line"
filename="${url##*/}"
filename="${filename//,/}"
wget -P /home/img/ "$url" -O "$filename"
Using -N and -O will both raise a warning message. The wget manual says:
-N (for checking the timestamp) is not supported in conjunction with -O: since the file is always created, it will always have a very new timestamp.
So when you use the -O option, it actually creates a new file with a new timestamp, and thus the option -N
becomes bogus (it cannot do what it is for). If you want to keep timestapming, then a workaround could be as follows:
url="$line"
wget -N -P /home/img/ "$url"
file="${url##*/}"
newfile="${filename//,/}"
[[ $file != $newfile ]] && cp -p /home/img/"$file" /home/img/"$newfile" && rm /home/img/"$file"
source to share