Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replace file line

Status
Not open for further replies.

cmancre

Programmer
Jan 30, 2005
35
0
0
PT
Hello
Any one knows how to replace a line in a file at the exact handler position.

exemple file:

hello
handler -> hello hello
hello
-------------------
replacing with guys will result:
hello
guys
hello
----------------
and not this
hello
guys hello
hello
------------------
thanks
 
/^.*$/guys/;

? (i am a Perl programmer - but i imagined this would be very similar)


Kind Regards
Duncan
 
/*------------------------------------------------*/
preg_match

(PHP 3 >= 3.0.9, PHP 4, PHP 5)
preg_match -- Perform a regular expression match
Description
int preg_match ( string pattern, string subject [, array &matches [, int flags [, int offset]]] )

Searches subject for a match to the regular expression given in pattern.

/*------------------------------------------------*/

There are a lot of C was of doing what you want. But you know what? Use duncdude's perl regular expression. It's just easier.
 
I did not get it wath to do with that? that's pattern matching. thanks
 
I have found the easiest way to work with a file is to read it into an array, do what needs to be done, then write it again. I suppose if it was a large file you could open two streams, reading the file then writing a temp file, read each line and write each line one at a time and modify the line you are looking for..

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top