LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 07-06-2006, 02:32 PM   #1
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 330

Rep: Reputation: 30
Multi line perl pie


Hey,

I am trying to replace a 6 line string in 123 files with a single command.

I tried this:

perl -p -i -e 'm/regular expression/new value/g'

and it says:

Bareword found where operator expected at -e line 1, near "m/WHTML.*WHTML/candy"
syntax error at -e line 1, near "m/WHTML.*WHTML/candy"
Execution of -e aborted due to compilation errors.

Any ideas of how I can get it to work?

Thanks,
David
 
Old 07-06-2006, 02:41 PM   #2
cupubboy
Member
 
Registered: May 2003
Location: Bucharest,Romania
Distribution: Fedora Core 7
Posts: 109

Rep: Reputation: 15
I forgot my regexp a long time ago unfotunatly

But I can at least say that m/ is for matching only .. s/ is for replace ... as I remember .. I may be wrong though
 
Old 07-06-2006, 02:45 PM   #3
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 330

Original Poster
Rep: Reputation: 30
I found a website that said use the m modifier to do multiline...
 
Old 07-06-2006, 04:30 PM   #4
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 51
modifiers go at the end. Specifically, the "m" modifier makes the "^" and "$" match only the beginning and end of the string (instead of beginning and end of lines), and the "s" modifier makes "." match newlines. So it seems that the "s" modifier is more what you need. try

s/regular expression/new value/gs
 
Old 07-06-2006, 10:21 PM   #5
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Try something like

Code:
perl -p -i -e 's/regular expression/new value/g;'  yourFileToParse
--- rod.
 
  


Reply



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
[Perl] multi table query dsheller Programming 4 11-03-2005 05:32 AM
help! perl multi-threading? eph Programming 0 05-03-2004 09:15 PM
grepping for multi-line output born4linux Programming 1 03-07-2003 02:26 AM
perl: writing multi files with one var bobjones Programming 2 09-26-2002 12:06 AM
multi send line m_m_zeus Linux - Networking 0 09-22-2002 05:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:23 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration