PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > changing part of a file name
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

changing part of a file name

Réponse
 
LinkBack Outils de la discussion
Vieux 26/03/2008, 17h50   #1
laredotornado
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut changing part of a file name

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
  Réponse avec citation
Vieux 26/03/2008, 18h49   #2
Scott McMillan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: changing part of a file name

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
  Réponse avec citation
Vieux 26/03/2008, 19h28   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: changing part of a file name

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
  Réponse avec citation
Vieux 26/03/2008, 19h35   #4
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: changing part of a file name

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.
  Réponse avec citation
Vieux 26/03/2008, 19h42   #5
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: changing part of a file name

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h28.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11538 seconds with 13 queries