Script for rename files.
Hello.
I have many files with .MP3 and .mkv suffix but after .MP3 and .mkv they have other characters. For example, guitar.mp3?1234yhh, How can I write a script that rename my files to a correct suffix? Tnx. |
What have you tried and where are you stuck? Searching both on this site and google would yield a plethora of results to aid any solution you require.
|
you do not need script, there is a command rename to do that.
|
Yes, "rename" is what you want, unless you really want to write your own script. Just be sure to use it with the -n option while figuring out the right patterns to use. As far as the patterns go, they are normal perl expressions, so anything perl works. You may have already encountered perl patterns in the form of PCRE.
|
Depends which "rename" is installed.
|
Quote:
|
Tell me about it - bloody annoying actually ... :rolleyes:
|
Quote:
|
i would hack around the file command to help print out the file type (maybe the -i argument to have it print out the mime-type).
|
Another command which you can use for such tasks is "mmv". To strip off everything after .mp3, you'd use:
Code:
mmv -v "*.mp3*" "#1.mp3" "*.mp3*" matches any file with ".mp3" in it, with two wildcards. Those wildcards will get mapped to #1 and #2. "#1.mp3" means the contents of the first wildcard (#1) plus ".mp3". The contents of the second wildcard (#2) are ignored. Note that this means there is a possibility of a name collision. But mmv has a built in safety check that will warn you if there is a name collision. If it detects a name collision, it will do nothing to the files. |
Lots of ways to do that. To the OP, you have 886 posts. Why haven't you studied even a little bash and regex?
Some examples: Code:
list=" Code:
for i in $list; do Code:
for i in $list; do Code:
for i in $list; do |
Can do this with parallel
Code:
parallel 'echo {1} {1.}.mp3; echo {2} {2.}.mkv' ::: *mp3* ::: *mkv* |
Perl rename (when rename script not installed :/)
Code:
cd /dir/of/files |
Quote:
|
and one more solution can be:
Code:
for f in *.mp3*; do |
All times are GMT -5. The time now is 04:23 AM. |