Skip to main content
Added a preventive code to use when downloading.
Source Link
tshiono
  • 22.3k
  • 2
  • 18
  • 26

If you want to rename the existing files, please try:

#!/bin/bash for f in *mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

It assumes the *mp4 files are located in the same directory. If you want to fix the filenames in the current directory recursively, please try:

#!/bin/bash shopt -s globstar for f in **/*mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

BTW if you want to fix the filenames downloading from now on, modify your awk command as:

awk '{url=$1; $1="";{sub(/ /,""); sub(/\r$/, "");out=url" -O \""$0"\""}; print out}' file.txt | xargs -L 1 wget 

It removes the trailing CR characters out of the names in file.txt then passes the corrected filenames to wget.

If you want to rename the existing files, please try:

#!/bin/bash for f in *mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

It assumes the *mp4 files are located in the same directory. If you want to fix the filenames in the current directory recursively, please try:

#!/bin/bash shopt -s globstar for f in **/*mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

If you want to rename the existing files, please try:

#!/bin/bash for f in *mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

It assumes the *mp4 files are located in the same directory. If you want to fix the filenames in the current directory recursively, please try:

#!/bin/bash shopt -s globstar for f in **/*mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

BTW if you want to fix the filenames downloading from now on, modify your awk command as:

awk '{url=$1; $1="";{sub(/ /,""); sub(/\r$/, "");out=url" -O \""$0"\""}; print out}' file.txt | xargs -L 1 wget 

It removes the trailing CR characters out of the names in file.txt then passes the corrected filenames to wget.

Source Link
tshiono
  • 22.3k
  • 2
  • 18
  • 26

If you want to rename the existing files, please try:

#!/bin/bash for f in *mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done 

It assumes the *mp4 files are located in the same directory. If you want to fix the filenames in the current directory recursively, please try:

#!/bin/bash shopt -s globstar for f in **/*mp4$'\r'; do mv -- "$f" "${f%$'\r'}" done