LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Search and Replace with multiple-line strings (http://www.linuxquestions.org/questions/programming-9/search-and-replace-with-multiple-line-strings-355143/)

ChristianNerds.com 08-20-2005 07:16 AM

Search and Replace with multiple-line strings
 
I'm not a new Linux user, but it's only recently that I've been working on using this OS exclusively. That being said, I'm more familiar with using X as my workplace, but am familiar enough with command line usage to use it if a GUI option isn't available.

Anyway, I run a website and do the vast vast majority of my coding direct, instead of a web editor. In windows, I had a program called ReplaceEm that I could copy and paste a bunch of code and then the stuff I'd like it to be replaced with and it would go through various files, changing every instance of that string. It's really handy.

I checked around the forums and found a number of perl answers to questions fairly similar to that, but they all involved single line replacement, where my applications are more of multi-line instances. Maybe there's just a carriage return text that I don't know that I could use in-line with the perl solutions, but I'm not sure.

Do you know of a multi-line text replacer progam? Preferably GUI, but not entirely necessary.

Luke

/bin/bash 08-20-2005 08:13 AM

Quote:

Do you know of a multi-line text replacer progam?
That would be sed.

sed 's/text to remove/text to replace/g' files.html

eddiebaby1023 08-20-2005 02:28 PM

Quote:

Originally posted by /bin/bash
That would be sed.

sed 's/text to remove/text to replace/g' files.html

I think the OP means his patterns span more than one line. However, sed can do multiple line matching but it's a bit convoluted and involves using (IIRC - not a facility I use very often!) the "join" operator to get extra lines into the pattern space. Have a google to find a sed tutorial online (or make your patterns single line!).

ChristianNerds.com 08-21-2005 04:31 AM

Just for the Record
 
I was going through Google looking for some good sed tutorials, only to find another program, called rpl, that has some pretty easy multi-line replace functionality. You just add an \n in the old string or new string to be interpreted as a newline. Then it turns out that it's in Debian Stable, and that's what I'm using.

So, anyone who reads this later, that may be an easier way to go about working on it. Especially if you're even slightly familiar with C, since that's the newline code in C. I've yet to find a GUI app using this (maybe I'll make one), but it's still none-the-less very handy.

Luke

/bin/bash 08-21-2005 02:32 PM

Quote:

I think the OP means his patterns span more than one line.
Yeah, I thought that answer was too easy. :p


All times are GMT -5. The time now is 06:47 AM.