473,387 Members | 1,295 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to do that

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
Jul 19 '05 #1
5 2069
Barti wrote:
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
Jul 19 '05 #2
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 ['*']


Jul 19 '05 #3
Barti wrote:
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
Jul 19 '05 #4
>
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?


Jul 19 '05 #5
"Barti" <ba**@spam-usun.sonik.pl> wrote in message news:<bv**********@nemesis.news.tpi.pl>...
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.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sentinel | last post by:
Hi, I'm currently writing a mulit-page form app that uses a session to retain data from each form element in order for the user to jump between pages, then the final data is passed to a calculation...
2
by: ChronicFatigue | last post by:
Given that some browsers dont have javascript enabled.... do developers try to avoid using javascript when a php alternative can be used? What sort of alternative php scripts are often used?
1
by: Timothy Rue | last post by:
I found the online and free PHP manual(s) but what I need is one that is plain text/ascii Is there such a beast and if not what is the closest to it? I'd like to do my own markup on it. ...
5
by: Nick Bartos | last post by:
I am looking for an open source php accelerator that works in cgi mode. I am guessing that to do that the cache would have to be on disk and not in memory. I was looking at the turk accelerator...
2
by: Martien van Wanrooij | last post by:
I am rather new at php so the answer to my question could be somewhere on the web but unfortunately I couldn't find it until now. I am using a form that is sent to me by email with the following...
4
by: Randell D. | last post by:
Folks, I use PHP to write my form data to MySQL. I have a database with about ten tables. I'm trying to fill one table with some dummy data (its a contact manager table holding names of...
3
by: simonc | last post by:
I'm getting incoming emails to activate a PHP script, not web page requests - so I can't visibly see things with a browser. Is there any way I can detect if one of my PHP scripts never exits -...
5
by: Beef Erikson | last post by:
Heya :) Ok... I've been thinking of a way to go about doing this, and I think I might have came up with it. Just wanting to run this by you guys, see what you think. Here's my setup: I...
3
by: Stijn Goris | last post by:
hi all, Does a function excist that converts a string to a string thats compatible with linux file system? kind regards Stijn
7
by: Jayne Wolps | last post by:
Hello I wonder if anyone can help. I would like to know how certain sites: http://aboutbritain.com/ArundelCastle.htm, and http://travel.knowhere.co.uk/place/+bristol-0/ manage to put approx...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.