|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
In a given directory, how do I change all file names such that I replace the string "show" with the string "event" in the file title? Thanks, - Dave |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Wed, 26 Mar 2008 09:50:06 -0700 (PDT), laredotornado
<laredotornado@zipmail.com> wrote: >Hi, > >In a given directory, how do I change all file names such that I >replace the string "show" with the string "event" in the file title? > >Thanks, - Dave Assuming "file title" means the filename, how about rename show event *show* ? Scott McMillan |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
2008-03-26, 09:50(-07), laredotornado:
[...] > In a given directory, how do I change all file names such that I > replace the string "show" with the string "event" in the file title? [...] If by "file title" you mean file name: With zsh autoload -U zmv # usually in ~/.zshrc zmv '(*)show(*)' '${1}event${2}' Or: zmv '*' '$f:s/show/event' -- Stéphane |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
laredotornado wrote:
> Hi, > > In a given directory, how do I change all file names such that I > replace the string "show" with the string "event" in the file title? If you have bash, you could do (case-sensitive): for name in *show*; do # replaces first occurrence of "show" newname="${name/show/event}" # to replace all occurrences, uncomment next line #newname="${name//show/event}" mv -- "$name" "$newname" done This should work even if filenames have strange characters in them (or at least seems to work in my tests; I've tried with filenames containing quotes, newlines, * and ?). -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
pk wrote:
> newname="${name/show/event}" It seems double quotes are not actually needed here: newname=${name/show/event} -- All the commands are tested with bash and GNU tools, so they may use nonstandard features. I try to mention when something is nonstandard (if I'm aware of that), but I may miss something. Corrections are welcome. |
|
![]() |
| Outils de la discussion | |
|
|