Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: How to rename a large number of messed up file names.

  1. #1
    Join Date
    Jul 2008
    Location
    Germany
    Beans
    30
    Distro
    Ubuntu Mate 14.04 Trusty Tahr

    How to rename a large number of messed up file names.

    Hello lads


    I've screwed up the names of a large batch of pdf-files with Krename with the result that the filenames contain the original name twice. They look like this:

    Code:
    10 ways to show off your ubuntu skills.pdf10 ways to show off your ubuntu skills.pdf
    Does anybody here know some magic that clears this up? I *think* it may be possible with rename (the pearl-script) but I'm a bit unsure about the syntax. Any help would be much appreciated.
    Last edited by ATSC; August 22nd, 2012 at 04:00 PM.

  2. #2
    Join Date
    Mar 2012
    Beans
    4

    Re: How to rename a large number of messed up file names.

    You can try 'pyRenamer' available in software center.

  3. #3
    Join Date
    Apr 2012
    Beans
    7,154

    Re: How to rename a large number of messed up file names.

    how about

    Code:
    rename -nv 's/(.*\.pdf)(.*\.pdf)/$1/' *.pdf
    (if it appears to match correctly take out the -n to run it for real)

  4. #4
    Join Date
    Oct 2009
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to rename a large number of messed up file names.

    Quote Originally Posted by steeldriver View Post
    how about

    Code:
    rename -nv 's/(.*\.pdf)(.*\.pdf)/$1/' *.pdf
    (if it appears to match correctly take out the -n to run it for real)
    This would work wonders. Perl is pretty awesome.

    I used that same command to replace underscores with spaces.
    Come to #ubuntuforums! We have cookies! | Basic Ubuntu Security Guide

    Tomorrow's an illusion and yesterday's a dream, today is a solution...

  5. #5
    Join Date
    Jul 2008
    Location
    Germany
    Beans
    30
    Distro
    Ubuntu Mate 14.04 Trusty Tahr

    Re: How to rename a large number of messed up file names.

    That seems to do the trick. Many, many thanks!



    /addendum: Is it possible to rename also all files in the subdirectories?
    Last edited by ATSC; August 22nd, 2012 at 04:30 PM.

  6. #6
    Join Date
    Jul 2008
    Location
    Germany
    Beans
    30
    Distro
    Ubuntu Mate 14.04 Trusty Tahr

    Re: How to rename a large number of messed up file names.


  7. #7
    Join Date
    Apr 2012
    Beans
    7,154

    Re: How to rename a large number of messed up file names.

    I *think* that with bash 4.x you should be able to use 'rename' with the bash globstar

    Code:
    rename -nv 's/(.*\.pdf)(.*\.pdf)/$1/' **/*.pdf
    However I have always used 'find -exec' for this kind of thing

    Code:
    find /path/to/top/dir -name '*.pdf' -exec rename -nv 's/(.*\.pdf)(.*\.pdf)/$1/' {} \;
    [although if there are MANY files this may overflow in which case you'd need to do something more clever (either using xargs or using a while loop to read the output from 'find' line-by-line)]
    Last edited by steeldriver; August 31st, 2012 at 05:26 PM. Reason: iname doesn't make sense here

  8. #8
    Join Date
    Jul 2008
    Location
    Germany
    Beans
    30
    Distro
    Ubuntu Mate 14.04 Trusty Tahr

    Re: How to rename a large number of messed up file names.

    That gives me a
    Code:
    Bareword "v" not allowed while "strict subs" in use at (eval 1) line 1.


    I also had a look onto pyRenamer and Krenamer again but I have difficulties to find the correct renaming pattern.
    Last edited by ATSC; August 31st, 2012 at 05:09 PM.

  9. #9
    Join Date
    Apr 2012
    Beans
    7,154

    Re: How to rename a large number of messed up file names.

    Which variant (the globstar version or the find version - or both)?

    For the globstar version, you will need bash > 4.something with globstar enabled, I think

    Code:
    $0 --version
    shopt globstar
    FWIW I tried both syntaxes before posting (Ubuntu 12.04 / bash 4.2.24) and they both appeared to work

    The error you are getting would appear to be from perl btw

  10. #10
    Join Date
    Jul 2008
    Location
    Germany
    Beans
    30
    Distro
    Ubuntu Mate 14.04 Trusty Tahr

    Re: How to rename a large number of messed up file names.

    I tried both - the result was the same. I use bash 4.1-2ubuntu3 and perl 5.1. (under Lucid).

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •