![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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? |
|
||||
|
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 |
|
||||
|
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. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|