Reputation: 1480
I have a bunch of files named like this:
file.jpg?sw=450&sh=450
I want to batch rename them removing that awful extension and get this:
file.jpg
I tried this script:
for file in *'.jpg?sw=450&sh=450'; do mv "$file" "${file%}".jpg; done
and also this script:
for file in *'.jpg?sw=450&sh=450'; do mv "$file" "${file%}'.jpg?sw=450&sh=450'".jpg; done
What happens is I get this result:
file.jpg?sw=450&sh=450.jpg
Upvotes: 0
Views: 82
Reputation: 3716
Bash is one way to do it, although I might consider use of rename
, which renames based on regular expressions. Consider:
$ rename 's/\.jpg\?.*$/.jpg/' *.jpg\?*
This says:
*.jpg\?*
/\.jpg\?.*$/
.jpg
Upvotes: 1