Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, I have several files as shown below: Code: 00126589.pdf$tp=&shelf=122899&chapter=3588 00126545.pdf$tp=&shelf=122899&chapter=3588 00124591.pdf$tp=&shelf=122899&chapter=3588 ... I want to batch rename them to the followings: Code: 00126589.pdf 00126545.pdf 00124591.pdf ... The files are ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2013
    Posts
    3

    Question rename several files


    Hi,
    I have several files as shown below:

    Code:
    00126589.pdf$tp=&shelf=122899&chapter=3588
    00126545.pdf$tp=&shelf=122899&chapter=3588
    00124591.pdf$tp=&shelf=122899&chapter=3588
    ...
    I want to batch rename them to the followings:

    Code:
    00126589.pdf
    00126545.pdf
    00124591.pdf
    ...
    The files are in one folder, but in many subfolders. All files are needed to be renamed as explained above.
    Any suggestions on how to do this?

    I am using Cygwin on Windows.

    Thank you for your help.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,665
    See the man page for the rename command. Example for your case:
    Code:
    rename '$tp=&shelf=122899&chapter=3588' '' *.pdf*3588
    I frequently use the rename command for similar situations.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Apr 2013
    Posts
    3
    Quote Originally Posted by Rubberman View Post
    See the man page for the rename command. Example for your case:
    Code:
    rename '$tp=&shelf=122899&chapter=3588' '' *.pdf*3588
    I frequently use the rename command for similar situations.
    Thank you for your reply. However, I have a typo in my original post.
    The files that are needed to be renamed do not have fixed part after "$tp=&shelf=" string. Please see the corrected file names below:

    Code:
    00126589.pdf$tp=&shelf=622559&chapter=3588
    00126545.pdf$tp=&shelf=824899&chapter=2998
    00124591.pdf$tp=&shelf=122490&chapter=6008
    ...
    How to rename these files in this case to the followings?
    Code:
    00126589.pdf
    00126545.pdf
    00124591.pdf
    ...
    Thank you for your help.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,665
    Please read the man page and try to resolve this yourself first. That comes from the "teach them to fish" department, not the "give me a fish" department...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,665
    Quote Originally Posted by Rubberman View Post
    Please read the man page and try to resolve this yourself first. That comes from the "teach them to fish" department, not the "give me a fish" department...
    To point you further in the correct direction, you may need to couple rename with a sed script wrapped in a shell script so the appropriate arguments are given to rename for each file found. I know you are a "newbie", but figuring this out will help you more than you know in working with linux. What I would recommend is that you first write up what needs to happen in pseudo-code, and then figure out what you need in a bash script to process it. Here is some pseudo-code to help you get started:
    Code:
    for each file in directory
        get file name
        extract the part after the .pdf - sed is good for this
        pass the extracted part as the first argument, an empty string as the second, and the file name as the third argument to rename
    endfor
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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