LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 08-20-2005, 07:16 AM   #1
ChristianNerds.com
LQ Newbie
 
Registered: Aug 2005
Location: Indiana, USA
Distribution: Debian
Posts: 2

Rep: Reputation: 0
Question 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
 
Old 08-20-2005, 08:13 AM   #2
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

Rep: Reputation: 46
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
 
Old 08-20-2005, 02:28 PM   #3
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
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!).
 
Old 08-21-2005, 04:31 AM   #4
ChristianNerds.com
LQ Newbie
 
Registered: Aug 2005
Location: Indiana, USA
Distribution: Debian
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 08-21-2005, 02:32 PM   #5
/bin/bash
Senior Member
 
Registered: Jul 2003
Location: Indiana
Distribution: Mandrake Slackware-current QNX4.25
Posts: 1,802

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a multiple file search and replace tool, prefer graphical haimeltjnfg Linux - Software 6 02-02-2005 10:53 PM
vim search and replace - split line phreak7t7 Programming 2 08-16-2004 05:02 PM
Search and Replace over multiple files The_Nerd Linux - Software 8 06-20-2004 06:59 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM


All times are GMT -5. The time now is 12:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration