The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Perl: FH and multiple writes gctaylor Shell Programming and Scripting 2 08-21-2008 10:14 AM
how does this substition work? wrapster Shell Programming and Scripting 1 05-31-2008 06:12 AM
Multiple conditions in find or ls stmts mavsman UNIX for Dummies Questions & Answers 5 04-01-2008 05:57 PM
multiple conditions in if/then grandtheftander UNIX for Dummies Questions & Answers 4 07-21-2006 02:58 PM
multiple conditions in if statements tim mauger Shell Programming and Scripting 3 04-28-2002 10:42 AM

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-25-2008
EDALBNUG EDALBNUG is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 14
Thumbs down Perl Substition with multiple conditions

I have a text file that contains lines similar to the following:

-----------------------------------------------------------
fall for setup

CSHRC0 'gnd';
CSHR0 'gnd';

rise for setup

rise for hold

CSHRC0 'gnd';
CSHR0 'gnd';

fall for hold
------------------------------------------------------------

I am trying to replace the gnd in between fall for setup and rise for setup with 0.75*vdd.

I tried the following:

Code:
perl -e 's/gnd/0\.75\*vdd/ if m/CSHRC0/ && /fall\ for\ setup/ .. /rise\ for\ setup/' -pi file
perl -e 's/gnd/0\.75\*vdd/ if m/CSHR0/ && /fall\ for\ setup/ .. /rise\ for\ setup/' -pi file

But these don't seem to work at all. I believe the problem is with how I am using the && operator to combine both conditions, since if I use any of those two conditions separately they would work. How can I apply multiple if conditions to the same substitution?
  #2 (permalink)  
Old 09-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Try parentheses.


Code:
perl -e 's/gnd/0\.75\*vdd/ if (m/CSHRC0/ && /fall\ for\ setup/ .. /rise\ for\ setup/)'

  #3 (permalink)  
Old 09-25-2008
EDALBNUG EDALBNUG is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 14
I tried using () and it still didn't change anything. Is this platform dependent? I think I am using UNIX with c shell right now.
  #4 (permalink)  
Old 09-25-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Sorry for the false diagnostic; it was a shot from the hip and I should have tested before posting. The real problem is in how /x/ .. /y/ is implemented -- it will fail to see the starting condition if the /CSHRC0/ condition in front of it fails! So just reverse those conditions.


Code:
perl -pe 's/gnd/0.75*vdd/ if /fall for setup/ .. /rise for setup/ && /CSHRC?0/'

I took out some redundant backslashes, too.

Are you replacing both occurrences of gnd? Then the single condition /CSHRC?0/ should cover both of those. Take out the question mark and adapt accordingly if that was not what you meant.

Last edited by era; 09-25-2008 at 03:52 PM.. Reason: Question mark in regex to cover both gnd occurrences
  #5 (permalink)  
Old 09-25-2008
EDALBNUG EDALBNUG is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 14
Thank you very much for the quick response. I tried reversing it, but somehow all the instances of gnd in the file got replaced by 0.75*vdd. So I tried Parentheses for the range condition and then it worked out fine.


Code:
perl -e 's/gnd/0\.75\*vdd/ if (/fall for setup/ .. /rise for setup/) && m/CSHRC?0/' -pi file

Thanks again for the help.
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 01:47 AM.


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