0

I'm trying to rename a bunch of files, using the rename command, from

Blue - This file is called Blue ok.txt
Red - This file is called Red ok.txt
Orange and Yellow - This file is called Orange and Yellow ok.txt

... into:

Blue.txt
Red.txt
Orange and Yellow.txt

I'm having trouble getting it to understand the wildcard in the middle. I've tried:

rename -f 's/ - This file is called* ok//gi' *.txt
beekay
  • 195
  • 5
  • Does this answer your question? [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) – ilkkachu Apr 25 '21 at 14:25
  • 2
    ... also [How do regular expressions differ from wildcards used to filter files](https://unix.stackexchange.com/questions/57957/how-do-regular-expressions-differ-from-wildcards-used-to-filter-files) – steeldriver Apr 25 '21 at 14:26
  • @steeldriver, yep, that's a better one, thanks. – ilkkachu Apr 25 '21 at 14:27
  • @ilkkachu for some reason it wouldn't let me suggest it as a duplicate (the button was grayed out) – steeldriver Apr 25 '21 at 14:28
  • Read the linked answers, but in short: the `d* ok` in your regex means zero-or-more `d` characters followed by " ok". You want `d.* ok`, which means `d` followed by zero-or-more of **any** character, followed by " ok". – cas Apr 26 '21 at 03:44

0 Answers0