The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find/replace to new file: ksh -> perl McLan Shell Programming and Scripting 1 05-16-2008 12:14 AM
Perl: Global Search and replace epi8 Shell Programming and Scripting 3 05-06-2008 12:18 PM
Search and replace in Perl jyoung Shell Programming and Scripting 2 04-22-2008 10:05 AM
Replace text in parentheses lalelle Shell Programming and Scripting 5 02-20-2008 06:52 PM
Replace Perl Module name in all Perl scripts rahulrathod Shell Programming and Scripting 2 12-01-2005 09:00 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-19-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Stumble this Post!
Parentheses in perl find/replace

I'm trying to use the following command to do a batch find and replace in all commonly named files through a file hierarchy

Code:
find . -name 'file' |xargs perl -pi -e 's/find/replace/g'
which works fine except for a substitution involving parenthesis.

As a specific example I'm trying to sub "G(d)" with "G('d,'p)."

The interpreter seems to just ignore the parentheses and not finding the string "Gd" simply does nothing. I can't just find/replace "d" as the character appears throughout the file.

Any help?
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-19-2007
Moderator
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,432
Stumble this Post!
What is the exact regular expression that you applied? It was likely not correct.
Reply With Quote
  #3 (permalink)  
Old 08-19-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 767
Stumble this Post!
"G(d)" matches the first occurance of string "Gd" and puts "d" in $1. To match string "G(d)" AS IS, use "G\(d\)"
Reply With Quote
  #4 (permalink)  
Old 08-21-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Stumble this Post!
Thanks to everyone for the help.

The regex I was using was incorrect, but a little reading took care of that.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
perl regex

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0