remove special characters in front of the file names
remove special characters in front of the file names
am 08.01.2008 20:07:51 von wong_powah
I want to remove all special characters in front of a list of file
names (which may be generated by the "find" or other commands).
How to do that?
This does not work:
$ find . -type f -print | perl -pe 's/([?|*.\'"])/\\$1/g'
>
$ find . -type f -print | perl -pe "s/([?|*.\'"])/\\$1/g"
bash: syntax error near unexpected token `)'
Re: remove special characters in front of the file names
am 08.01.2008 20:58:48 von jurgenex
wong_powah@yahoo.ca wrote:
>I want to remove all special characters in front of a list of file
>names (which may be generated by the "find" or other commands).
>How to do that?
>This does not work:
Unfortunately you forgot to tell in which way the expected behaviour is
different from the observed behaviour, i.e. WHAT IS THE PROBLEM?
>$ find . -type f -print | perl -pe 's/([?|*.\'"])/\\$1/g'
So I can only guess that this s/// does additional unwanted substitutions in
the middle of the text. This is because you forgot to anchor the RE to the
beginning of the string.
jue
Re: remove special characters in front of the file names
am 08.01.2008 21:01:38 von someone
wong_powah@yahoo.ca wrote:
> I want to remove all special characters in front of a list of file
> names (which may be generated by the "find" or other commands).
> How to do that?
> This does not work:
> $ find . -type f -print | perl -pe 's/([?|*.\'"])/\\$1/g'
> $ find . -type f -print | perl -pe "s/([?|*.\'"])/\\$1/g"
> bash: syntax error near unexpected token `)'
find . -type f -print | perl -pe 's/([?|*.\047"])/\\$1/g'
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Re: remove special characters in front of the file names
am 08.01.2008 21:12:43 von wong_powah
On Jan 8, 2:58 pm, Jürgen Exner wrote:
> wong_po...@yahoo.ca wrote:
> >I want to remove all special characters in front of a list of file
> >names (which may be generated by the "find" or other commands).
> >How to do that?
> >This does not work:
>
> Unfortunately you forgot to tell in which way the expected behaviour is
> different from the observed behaviour, i.e. WHAT IS THE PROBLEM?
>
> >$ find . -type f -print | perl -pe 's/([?|*.\'"])/\\$1/g'
>
> So I can only guess that this s/// does additional unwanted substitutions =
in
> the middle of the text. This is because you forgot to anchor the RE to the=
> beginning of the string.
>
> jue
The problem is that a '>' appear for
$ find . -type f -print | perl -pe 's/([?|*.\'"])/\\$1/g'
>
Sorry, I don't understand the meaning of "to anchor the RE to the
beginning of the string."
Do you mean:
$ find . -type f -print | perl -pe 's/^([?|*.\'"])/\\$1/g'
>
$ find . -type f -print | perl -pe "s/^([?|*.\'"])/\\$1/g"
bash: syntax error near unexpected token `)'
Both does not work:(.
Re: remove special characters in front of the file names
am 08.01.2008 21:18:08 von wong_powah
e.g. for this output:
$ find . -type f -print
../VERSION
../RELEASE
My desired output will be:
VERSION
RELEASE
This does not work:
$ find . -type f -print | perl -pe 's/([?|*.\047"])/$1/g'
../VERSION
../RELEASE
Re: remove special characters in front of the file names
am 08.01.2008 21:22:41 von it_says_BALLS_on_your forehead
On Jan 8, 3:18=A0pm, wong_po...@yahoo.ca wrote:
> e.g. for this output:
> $ find . -type f -print
> ./VERSION
> ./RELEASE
>
> My desired output will be:
> VERSION
> RELEASE
>
> This does not work:
> $ find . -type f -print | =A0perl -pe 's/([?|*.\047"])/$1/g'
> ./VERSION
> ./RELEASE
try:
find . -type f -print | perl -pe 's/^\W+//'
Re: remove special characters in front of the file names
am 08.01.2008 21:26:23 von Ted Zlatanov
On Tue, 8 Jan 2008 12:18:08 -0800 (PST) wong_powah@yahoo.ca wrote:
wp> e.g. for this output:
wp> $ find . -type f -print
wp> ./VERSION
wp> ./RELEASE
wp> My desired output will be:
wp> VERSION
wp> RELEASE
wp> This does not work:
wp> $ find . -type f -print | perl -pe 's/([?|*.\047"])/$1/g'
wp> ./VERSION
wp> ./RELEASE
You mean you want the base name? This will do what you're asking in the
example above (you don't need Perl necessarily):
find . -type f -exec basename {} \;
Are you trying to do something else? Show some more examples (what you
had above was great, by the way).
Ted
Re: remove special characters in front of the file names
am 08.01.2008 23:20:13 von jurgenex
wong_powah@yahoo.ca wrote:
>e.g. for this output:
>$ find . -type f -print
>./VERSION
>./RELEASE
>
>My desired output will be:
>VERSION
>RELEASE
>
>This does not work:
>$ find . -type f -print | perl -pe 's/([?|*.\047"])/$1/g'
>./VERSION
>./RELEASE
I have a _very_ strong suspicion that we are looking at an x-y-problem.
You want to achieve something and you believe, removing "special" characters
from the beginning of the string is the best way to do it. Therefore you are
asking how to remove special characters. That would be the Y.
From you sample data I gather you are dealing with file names and I'm
guessing you want to get the basename of the file. That would be the X.
The right tool to do that would be File::Basename.
As for blindly removing those characters that you mentioned earlier
[?|*.\'"] are you aware, that in most file system many if not all of them
can be part of a regular file name? Do you really want to change the file
name if it starts with one of your "special" characters?
jue
Re: remove special characters in front of the file names
am 09.01.2008 21:29:16 von wong_powah
On Jan 8, 3:26 pm, Ted Zlatanov wrote:
> On Tue, 8 Jan 2008 12:18:08 -0800 (PST) wong_po...@yahoo.ca wrote:
>
> wp> e.g. for this output:
> wp> $ find . -type f -print
> wp> ./VERSION
> wp> ./RELEASE
>
> wp> My desired output will be:
> wp> VERSION
> wp> RELEASE
>
> wp> This does not work:
> wp> $ find . -type f -print | perl -pe 's/([?|*.\047"])/$1/g'
> wp> ./VERSION
> wp> ./RELEASE
>
> You mean you want the base name? This will do what you're asking in the
> example above (you don't need Perl necessarily):
>
> find . -type f -exec basename {} \;
>
> Are you trying to do something else? Show some more examples (what you
> had above was great, by the way).
>
> Ted
It turns out that all I want is the dirname and basename.
Thanks.