![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| Extract a substring using regular expression | apraja | Shell Programming and Scripting | 2 | 03-04-2008 05:47 PM |
| how to extract a substring froma file | morena | UNIX for Dummies Questions & Answers | 1 | 01-23-2008 07:22 PM |
| help for shell script of finding shortest substring from given string by user | pankajd | Shell Programming and Scripting | 1 | 11-22-2007 12:27 PM |
| Using Awk in shell script to extract an index of a substring from a parent string | sandeepms17 | Shell Programming and Scripting | 2 | 11-07-2007 07:44 AM |
| can i get a substring from a string? | dell9 | High Level Programming | 4 | 11-06-2001 09:13 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
command/script to extract a substring from a string
I have a long string "<ID type="Oid">{[ManagedElement(Key=rvpdn-nvl-mayo-17)][PhysicalRoot][Chassis][Slot(SlotNum=10000)][Module][Port(PortNumber=GigabitEthernet0/1)][PhysicalLayer][DataLinkLayer]}</ID>"
I need to extract "GigabitEthernet0/1" from the above string. How can it be done? ![]() |
|
||||
|
alternatively in Python:
Code:
#!/usr/bin/python
import re
longstring = '"<ID type="Oid">{[ManagedElement(Key=rvpdn-nvl-mayo-17)][PhysicalRoot][Chassis][Slot(SlotNum=10000)][Module][Port(PortNumber=GigabitEthernet0/1)][PhysicalLayer][DataLinkLayer]}</ID>"'
get = re.findall(".*PortNumber=(.*)\)",longstring)
print get
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|