You are not logged in.
Pages: 1
I volunteered to download my school's entire website, as the current host is going into liquidation and they can't get a copy of the database. So I downloaded the whole thing with wget. Now, the problem is that many (several hundred) of the files have names like "featureDetails.asp?featureID=2", which is fine on a JFS partition, but can't be on a FAT partition.
So, my question is, how do I replace all "?"s, and "="s with "-"?
PS: I really have no idea where to post this, so picked this board at random
Offline
If it's just a matter of renaming the files then you can use something line this:
for i in *; do j=$(echo "$i" | sed 's/?/-/g;s/=/-/g'); mv "$i" "$j"; done
This will rename all files in the current directory.
EDIT:
or something like this would work as well:
for i in *; do j=$(echo "$i" | sed 's/[?=]/-/g'); echo "$i" "$j"; done
Last edited by fwojciec (2008-12-09 17:08:52)
Offline
Wonderful, I now have about 1000 files that FAT will be happy with. Thanks.
Offline
I recommend using:
mv --backup=t --
to automatically solve overwrites
EDIT: never mind, there is no real danger of filename conflicts in this situation.
Last edited by Procyon (2008-12-09 23:17:31)
Offline
If it's just a matter of renaming the files then you can use something line this:
for i in *; do j=$(echo "$i" | sed 's/?/-/g;s/=/-/g'); mv "$i" "$j"; done
This will rename all files in the current directory.
EDIT:
or something like this would work as well:for i in *; do j=$(echo "$i" | sed 's/[?=]/-/g'); echo "$i" "$j"; done
These certainly work, and for small jobs they are reasonable, but they are both very inefficient because a new process is forked for every file to be renamed. Instead consider this:
for i in *; do mv "$i" "${i//\?/-/}" ; done
This syntax is documented in the "Parameter Expansion" portion of the bash(1) manpage.
Offline
@tam1138 This is cool. I'm always confused about parameter expansion in bash, for some reason, but now I'll remember this one
Offline
man rename
Offline
Pages: 1