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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Replacement of sed with perl dbsurf Shell Programming and Scripting 4 01-25-2008 06:21 PM
String Replacement Script jbud Shell Programming and Scripting 6 11-15-2007 06:37 AM
Need shell/sed script for grep+string replacement pranavagarwal Shell Programming and Scripting 3 11-15-2007 06:35 AM
sed problem - replacement string should be same length as matching string. amangeles Shell Programming and Scripting 4 01-11-2006 06:11 AM
String replacement in multiple files WABonnett Shell Programming and Scripting 2 02-17-2004 03:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2006
Lindarella Lindarella is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 12
String Replacement with Perl

I want to replace a string within a file using perl.

We have a line that gets commented out, and I want to replace that line now matter how it was commented out.

for example, I'd want to replace

###ES=PR1A with ES=PR1A

or

##LJW(9/16/26)ES=PR1A with ES=PR1A


I tried: perl -pi -e 's/ES=PR1A\Z/ES=PR1A/' filename

but the comments are not removed.

Thank you in advance for any guidance you can give..

Linda
  #2 (permalink)  
Old 09-29-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
I don't know perl, but could this work?
Code:
perl -pi -e 's/^#*//1' filename

  #3 (permalink)  
Old 09-29-2006
Lindarella Lindarella is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 12
Wouldn't that remove the comments from every line?


I just want to remove comments from a line that contains a particular string
  #4 (permalink)  
Old 09-29-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
Woops, my mistake. Try:
Code:
perl -pi -e 's/^#*ES=PR1A/ES=PR1A/1' filename

In any case, what I'm getting at is that with sed, you could do
Code:
echo "#abc
###abc
##abc" | sed 's/^#*abc/abc/1'

  #5 (permalink)  
Old 09-29-2006
Lindarella Lindarella is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 12
AHA! worked beautifully.

Thank you so much !
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0