0

This command finds files if I remove from exec onwards.

find src -name "*.tsx" -o -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

The LayerSelector is indeed in most of those files, and the -i should replace in place.

However, nothing happens. No changes in files, no message.

What is wrong with this simple command ?


However, this works fine:

sed -i "" "s/LayerSelector/LayerRenderer/g" src/**/*.tsx
Minsky
  • 2,277
  • 10
  • 19
  • Why the `""` ? I'd think you should remove it. – stevesliva Jun 15 '23 at 18:27
  • 2
    @stevesliva That's requited by bsd (/macOS) version of `sed` if you want to pass `-i` without a backup file extension; see ["sed in-place flag that works both on Mac (BSD) and Linux"](https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux). – Gordon Davisson Jun 15 '23 at 19:07

1 Answers1

3

You are missing parentheses around the -o clause:

find src \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

Without the parentheses, due to operator precedence, this:

find src -name "*.tsx" -o -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

is the same as this (which is probably not what you want, because it does nothing to "*.tsx" files):

find src \( -name "*.tsx" \) -o \( -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \; \)

See also:

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47