Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid result with capture variables #33

Closed
gdommergue opened this issue Jan 25, 2024 · 3 comments
Closed

Invalid result with capture variables #33

gdommergue opened this issue Jan 25, 2024 · 3 comments

Comments

@gdommergue
Copy link

I have the following files in my folder:

pic_F01P01.jpg
pic_F01P02.jpg
pic_F01P03.jpg

I want to obtain:

F01P01.jpg
F01P02.jpg
F01P03.jpg

I was expecting this command to work, but it's not:

brename -p ".*F(\d\d)P(\d\d).*\.jpg" -r 'F$1P$2.jpg' -d
Searching for paths to rename...

  [OK] pic_F01P01.jpg -> F01.jpg
  [OK] pic_F01P02.jpg -> F02.jpg
  [OK] pic_F01P03.jpg -> F03.jpg

3 path(s) to be renamed

If i add a non alpha character to separate the $1 and the P, it works:

brename -p ".*F(\d\d)P(\d\d).*\.jpg" -r 'F$1-P$2.jpg' -d
Searching for paths to rename...

  [OK] pic_F01P01.jpg -> F01-P01.jpg
  [OK] pic_F01P02.jpg -> F01-P02.jpg
  [OK] pic_F01P03.jpg -> F01-P03.jpg

3 path(s) to be renamed

Exact same thing happens if i use -r "F\$1P\$2.jpg"
I'm on Ubuntu 22.04.3

@shenwei356
Copy link
Owner

Simply due to variable names.

$1P$2 represents $1P and $2. So you need to add brackets, using ${1}P${2}.

$ brename -p ".*F(\d\d)P(\d\d).*\.jpg" -r 'F${1}P$2.jpg' -d
Searching for paths to rename...

  [OK] pic_F01P01.jpg -> F01P01.jpg
  [OK] pic_F01P02.jpg -> F01P02.jpg
  [OK] pic_F01P03.jpg -> F01P03.jpg

3 path(s) to be renamed

@gdommergue
Copy link
Author

Great, working like a charm now, good to know that, thanks for the fast reply!

@shenwei356
Copy link
Owner

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants