0

how i can rename USB-(DOT4)- to USB-DOT4- i am using debian 10 i have tried so many commands nothing working i have several files inside sub-folders with similar word please help

i have tried the following commands

grep -RiIl 'search' | xargs sed -i 's/(USB-DOT4)/USB-DOT4/g'
find ./ -type f -exec sed -i 's/(USB-DOT4)/USB-DOT4/gI' {} \;
grep -rli '(USB-DOT4)' * | xargs -i@ sed -i 's/(USB-DOT4)/USB-DOT4/g' @
sed -i 's/-(USB-DOT4)-/-USB-DOT4-/g' *.exe
mmv USB-DOT4\* Installer\#1
mmv '*(USB-DOT4)*' '#1USB-DOT4#2'
rename 's/(USB-DOT4)/USB-DOT4/g' *
Gilles Quénot
  • 31,569
  • 7
  • 64
  • 82
  • You say you want to *rename `USB-(DOT4)-` to `USB-DOT4-`* but all your attempts seem to want to rename `(USB-DOT4)` to `USB-DOT4`. Which is it? – Stéphane Chazelas Apr 24 '23 at 05:33
  • in which way are the ones similar? What do they have in common, what's the factor that should make you decide you want to rename them? Are there also `SCSI-{COMA5}` you want to rename to `SCSI-COMA5` for instance? – Stéphane Chazelas Apr 24 '23 at 05:39

1 Answers1

0

Using Perl's rename:

$ find . -type f -name '*USB-*' -print0 | rename -n -d -0 's/[()]//g'
# USB-(DOT4)-  =>   USB-DOT4-

Remove -n switch, aka dry-run when your attempts are satisfactory to rename for real.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
Gilles Quénot
  • 31,569
  • 7
  • 64
  • 82
  • Worth noting: perl rename can take filenames from stdin as well as on the command line, even NUL separated using the `-0` option. So the "multiple directories" part of the question can be satisfied with `find . -type f -print0 | rename -n -0 's/[()]//g'` – cas Apr 24 '23 at 05:09