Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Need a REGEX to increment the file number of a pdf file

  1. #11
    Join Date
    Mar 2011
    Beans
    32

    Re: Need a REGEX to increment the file number of a pdf file

    Quote Originally Posted by ofnuts View Post
    Don't use '019' but '19'. When you write '019' it is assumesd to be a number in octal notation (in which '9' isn't a valid digit)....

    May I point out that the code by my esteemed co-posters requires you to first spot any duplicates, while my suggestion can be applied blindly?


    OK, thank you, that worked. I also see the wisdom of using your program as it reorders from start to finish, thanks for pointing that out. I'm very new to any programming so I started with the easiest to read. I have a question about reading your code:

    count=$(( $count + 1 ))
    I understand increments and saves count...then:

    count0="000$count"
    What's here, count0 is assigned 0001?

    renumbered="${count0: -3}_${file#???_}"
    THEN, get a little mixed up. Takes file number whatever say 256_ (puts in $)....then count0 (or 0001): -3 ...this lost me
    so what is ${count0: -3} saying exactly?

    [[ "$file" != "$renumbered" ]] && echo mv -v "$file" "$renumbered"
    I think I understand this: (& finally pop out the echo when test succeeds)

    OK, other than my lack of coding knowledge I think you found the best solution to my issue.
    Thanks again.

  2. #12
    Join Date
    Feb 2013
    Beans
    Hidden!

    Re: Need a REGEX to increment the file number of a pdf file

    $count0 just pads $count on the left with 000, then ${count0: -3} takes only the three rightmost characters of it. That gives

    $count $count0 ${count0: -3}
    1 0001 001
    23 00023 023
    456 000456 456
    Last edited by schragge; March 29th, 2013 at 07:05 PM.

  3. #13
    Join Date
    Mar 2011
    Beans
    32

    Re: Need a REGEX to increment the file number of a pdf file

    Thank you very much, and I completely understand now.

  4. #14
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Need a REGEX to increment the file number of a pdf file

    about that zero forcing octal system where 9 is illegal: you can easily circumvent that issue and force decimal system

    Code:
    $ x=019
    $ printf "%03d\n" $(( x+5 ))  # pad with 0s to 3digits
    bash: 019: value too great for base (error token is "019")
    $ printf "%03d\n" $(( 10#$x+5 ))
    024
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  5. #15
    Join Date
    Mar 2011
    Beans
    32

    Re: Need a REGEX to increment the file number of a pdf file

    .........Since the upgrade of the forum there's still a problem with the option to mark the threads as solved in the Thread Tools combo. The workaround is to edit the thread Title and inserting [SOLVED] at the beginning of it............

    I've been trying to close this thread. I do not have the ability to do this in thread tools or in go advanced.

Page 2 of 2 FirstFirst 12

Tags for this Thread

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
  •