You are not logged in.
Pages: 1
I've been googling since few hours, but I found nothing what I could use.
I need to remove last 12 characters from many files at one, and because those files are huge, it cannot be copy, but just rename action (and 'sed' seems to be copying it before renaming).
How could I do that?
Last edited by Lockheed (2013-07-13 17:38:26)
Offline
Are the last 12 characters the same for each file? If so, the rename command is a simple way to do it. If they're not the same, a script could get the last 12 characters and then use rename.
Online
No, they are different for every file and can be either letters or digits. I found a great tool called ReNamer which can do it in a blink of an eye. They only drawback is it's for Windows and I have to use it inside virtual machine.
Last edited by Lockheed (2013-07-12 16:01:26)
Offline
How different are the characters? If they follow a fairly obvious pattern, you could use a for loop coupled with `rename` or `mv` to do this pretty effectively.
All the best,
-HG
Last edited by HalosGhost (2013-07-12 16:09:18)
Offline
you can write a shell script to do this
for f in *
do
mv $f ${f:0:-10}
done
Apple hater. Panda lover.
Offline
Use "vidir" from the package "moreutils". It allows you to change file names by using Vim commands.
For your example, I would:
qa (start recording a macro called "a")
$ (go to the end of the line)
11h (move the cursor to the twelth character to the left)
12x (delete 12 characters to the right)
0 (go to the beginning of the line)
j (go to the next line)
q (stop recording a macro)
1000@a (run the macro called "a" on the next 1000 lines)
...I'm sure someone has a much more elegant way of doing it, but hey, there's a solution, and it would have taken me about 20 seconds.
Offline
args' script works, but
* OP wanted to remove last 12 characters, not 10 :-)
* all files have to be of valid length, or else you get
./<scriptname>: line 5: -10: substring expression < 0
(filename was too short).
Last edited by karol (2013-07-12 16:22:02)
Offline
Give metamorphose2 a try. It is in the AUR.
Offline
Wait, how come nobody has mentioned perl-rename?
@args, dude quote your $shit or it's gonna leak.
Last edited by lolilolicon (2013-07-12 17:18:44)
This silver ladybug at line 28...
Offline
Wait, how come nobody has mentioned perl-rename?
I want to be cheeky and say "because it's Perl", but I was the person that recommended using Vim...
EDIT: More specifically, crazy Perl regular expressions...
EDIT EDIT: I think nobody has mentioned it because nobody can figure out how to use it. What command would you use to fix the OP's problem?
Last edited by drcouzelis (2013-07-12 17:28:48)
Offline
There must some trap here... but I'll risk being a fool now...
perl-rename 's/.{12}$//' *
This silver ladybug at line 28...
Offline
I just realized a very nice and somewhat unique feature to vidir: You can see what the "results" will be before committing to the renaming.
Offline
perl-rename can dry run and show it to you if you give it -n, too.
This silver ladybug at line 28...
Offline
perl-rename can dry run and show it to you if you give it -n, too.
Very cool! I knew this thread was going to be a learning experience for me.
Offline
Thunar has a built in bulk renamer, but I've never used it.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline
You might want to check if there will be any dupes after renaming the files.
$ ls
abc123 abc456 abc789
$ perl-rename -n 's/.{3}$//' *
abc123 -> abc
abc456 -> abc
abc789 -> abc
Without the dry run
$ perl-rename 's/.{3}$//' *
$ ls
abc
Edit: added pics
Thunar's bulk rename will not let you make any changes if you would end up with some dupes(afaict). The rename button is greyed out.
pic of greyed out button http://i.imgur.com/yJS5Alt.jpg
If you didn't put all the files into bulk rename in your current dir and you would end up with some dupes after renaming, bulk rename will give you an error message.
pic of failed to rename http://i.imgur.com/pbBLNjD.jpg
Last edited by stewie (2013-07-12 22:01:43)
We wants it, we needs it. Must have the precious. Arch Linux.
Offline
there is pyrenamer which has extensive options which include delete number of characters of file
Last edited by dag (2013-07-12 21:53:46)
--------------------------------------
alcoves wonder creates the wonder unto the ages; never lose that.
Offline
For a lazy GUI try gprename
Offline
@stewie, good point wrt dupes after rename. One could avoid it by using the '-i' option so it prompts before overwriting, or by making backups, e.g.
perl-rename -b -V numbered 's/.{12}$//' *
This silver ladybug at line 28...
Offline
Wow almost every single person has responded with a different program. Maybe there should be "Which file renamer do you use thread"
Last edited by x33a (2013-07-13 08:43:15)
Offline
I learnt a lot thanks to your suggestions.
In the end, I found metamorphose2 recommended by x33a as the most versatile and convenient to me solution, which does exactly what I wanted.
Thanks, guys!
Offline
There're also renameutils with their qmv that works similarly to vidir https://bbs.archlinux.org/viewtopic.php … 0#p1299390
Lockheed, please remember to mark the thread as solved https://bbs.archlinux.org/viewtopic.php?id=130309
Offline
Pages: 1