how to do that

B

Barti

I have lot of files in lot of dirs
I need change
[text]
into
['text']
but! text is not constans
so I ned find
[*]
and change in to
['*']

barti
linux
 
J

Jürgen Exner

Barti said:
I have lot of files in lot of dirs

See perldoc File::Find
I need change

See perldoc -q change
"How do I change one line in a file/delete a line in a file/insert a line in
th
e middle of a file/append to the beginning of a file?"
[text]
into
['text']
but! text is not constans
so I ned find
[*]
and change in to
['*']

See perldoc perlre
and perldoc perlretut

Actually, why don't you show us the code you have so far?
Then it would be much easier to find and fix any problems with it.

jue
 
B

Barti

Actually, why don't you show us the code you have so far?
Then it would be much easier to find and fix any problems with it.

To tell you the truth I have no code.
I need in my php files change this.
I do not want to do that one by one (too many hours!) and
I don't know perl at all but I know that perl with find can do that

I have somethig like this to change one word in another
find -type f -name '*.*' -exec perl -pi -e 's/word/anotherword/;' {} \;
but this situation is diffrent because I need find strings match pattern
[*] where * is wahtever and change into ['*']
 
J

Jürgen Exner

Barti said:
Actually, why don't you show us the code you have so far?
Then it would be much easier to find and fix any problems with it.

To tell you the truth I have no code.
I need in my php files change this.
I do not want to do that one by one (too many hours!) and
I don't know perl at all but I know that perl with find can do that

I have somethig like this to change one word in another
find -type f -name '*.*' -exec perl -pi -e 's/word/anotherword/;' {}
\; but this situation is diffrent because I need find strings match
pattern [*] where * is wahtever and change into ['*']

Again, "perldoc perlretut" is your friend.
<quote>
Extracting matches

The grouping metacharacters "()" also serve another completely different
function: they allow the extraction of the parts of a string that
matched. This is very useful to find out what matched and for text
processing in general. For each grouping, the part that matched inside
goes into the special variables "$1", "$2", etc. They can be used just
as ordinary variables:

# extract hours, minutes, seconds
$time =~ /(\d\d):(\d\d):(\d\d)/; # match hh:mm:ss format
$hours = $1;
$minutes = $2;
$seconds = $3;
</quote>

Just use that $1, $2, $3, ... in the substitution string.

jue
 
O

Oliver Frick

I have somethig like this to change one word in another
find -type f -name '*.*' -exec perl -pi -e 's/word/anotherword/;' {} \;
but this situation is diffrent because I need find strings match pattern
[*] where * is wahtever and change into ['*']

what you mean exactly, do you want do change, say [January] in ['January'],
[January 2003] in ['January 2004'], or change [whatever] into ['something
other'],
and how you want to use your script? Just with 2 words for search and
replace,
or more than this?
 
A

Aaron Sherman

Barti said:
I have lot of files in lot of dirs
I need change
[text]
into
['text']

The simple answer is:

s/\[(.*?)\]/$1/g;

But, that's not really correct because you might be dealing with
nested brackets. If you are, then you need Text::Balanced. See:

http://www.perldoc.com/perl5.8.0/lib/Text/Balanced.html

Matching balanced characters like parens or brackets is easy in a CS
sense, but hard in practice in Perl and just about anything else but
Snobol. Text::Balanced bridges that gap.

Enjoy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top