Re: [OT] perlexpr : Rekursive Entfernung einzelner Zeichen aus Datei- und Ordnernamen mit find & rename
Hallo DIrk!
DIrk Wernien schrieb am Donnerstag, den 05. November 2009:
> Am Donnerstag, 5. November 2009 schrieb Christian Brabandt:
>
> > Sicher, dass da ein $ nach dem : stehen muß? Das würde doch nur
> > funktionieren, wenn der : das letzte Zeichen ist, oder? Ich würde mal
> > ein rename 'y/://' probieren. Aber ich kenne rename auch nicht und
> > rate jetzt nur.
>
> Raten hilft nicht weiter - warten (auf einen Perl-Spezialisten) ist wohl
> besser ;-)
Stimmt, also lesen wir mal die Doku (jetzt wird es aber fundiert ;)):
perldoc perlop und suchen nach y\/
,----
| y/SEARCHLIST/REPLACEMENTLIST/cds
|
| Transliterates all occurrences of the characters found in the search
| list with the corresponding character in the replacement list. It
| returns the number of characters replaced or deleted. If no string is
| specified via the =~ or !~ operator, the $_ string is transliterated.
| (The string specified with =~ must be a scalar variable, an array
| element, a hash element, or an assignment to one of those, i.e., an
| lvalue.)
|
| A character range may be specified with a hyphen, so "tr/A-J/0-9/" does
| the same replacement as "tr/ACEGIBDFHJ/0246813579/". For sed devotees,
| "y" is provided as a synonym for "tr". If the SEARCHLIST is delimited
| by bracketing quotes, the REPLACEMENTLIST has its own pair of quotes,
| which may or may not be bracketing quotes, e.g., "tr[A-Z][a-z]" or
| "tr(+\-*/)/ABCD/".
|
| Note that "tr" does not do regular expression character classes such as
| "\d" or "[:lower:]". The "tr" operator is not equivalent to the tr(1)
| utility. If you want to map strings between lower/upper cases, see "lc"
| in perlfunc and "uc" in perlfunc, and in general consider using the "s"
| operator if you need regular expressions.
|
| Note also that the whole range idea is rather unportable between
| character sets--and even within character sets they may cause results
| you probably didn't expect. A sound principle is to use only ranges
| that begin from and end at either alphabets of equal case (a-e, A-E), or
| digits (0-4). Anything else is unsafe. If in doubt, spell out the
| character sets in full.
|
| Options:
|
| c Complement the SEARCHLIST.
| d Delete found but unreplaced characters.
| s Squash duplicate replaced characters.
|
| If the "/c" modifier is specified, the SEARCHLIST character set is
| complemented. If the "/d" modifier is specified, any characters
| specified by SEARCHLIST not found in REPLACEMENTLIST are deleted. (Note
| that this is slightly more flexible than the behavior of some tr
| programs, which delete anything they find in the SEARCHLIST, period.) If
| the "/s" modifier is specified, sequences of characters that were
| transliterated to the same character are squashed down to a single
| instance of the character.
`----
also probieren wir jetzt:
find ./ -name "*:*" -exec rename 'y/://d' '{}' \;
Eine Alternative dazu wäre wohl mmv:
while mmv '*:*' '#1#2'; do :; done
> Die Manpage erklärt auch nicht wirklich etwas:
> Das y oder das s am Beginn, wofür ist das gut?
y kommt wohl ursprünglich von sed, wo es dem tr-Befehl entspricht.
s wiederum steht für substitute.
Grüße
Christian
--
:wq
Reply to: