Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
08-20-2005, 07:16 AM
|
#1
|
LQ Newbie
Registered: Aug 2005
Location: Indiana, USA
Distribution: Debian
Posts: 2
Rep:
|
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
|
|
|
08-20-2005, 08:13 AM
|
#2
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
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
|
|
|
08-20-2005, 02:28 PM
|
#3
|
Member
Registered: May 2005
Posts: 378
Rep:
|
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!).
|
|
|
08-21-2005, 04:31 AM
|
#4
|
LQ Newbie
Registered: Aug 2005
Location: Indiana, USA
Distribution: Debian
Posts: 2
Original Poster
Rep:
|
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
|
|
|
08-21-2005, 02:32 PM
|
#5
|
Senior Member
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802
Rep:
|
Quote:
I think the OP means his patterns span more than one line.
|
Yeah, I thought that answer was too easy.
|
|
|
All times are GMT -5. The time now is 10:04 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|