Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep portion of a string using sed

Status
Not open for further replies.

viadisky

Technical User
Jun 19, 2003
110
GB
Hi,

I submitted this query before and Feherke kindly provided solution: (thread822-1198142)

I'm trying to use the same sed command to format my data but I think I missed something because it's not providing the result I'm expecting.

My original data looks like this:

MRTG$ grep -i "System" $file

<H1>Traffic Analysis for 15 -- sERITHC3602.t-mobile.co.uk</H1> <TABLE> <TR><TD>System:</TD> <TD>sERITHC3602 in </TD></TR> <TR><TD>Maintainer:</TD> <TD></TD></TR> <TR><TD>Description:</TD><TD>ATM2/0.4-aal5 layer VC link to sCRDONC3601 ATM2/0.1 </TD></TR> <TR><TD>ifType:</TD> <TD>aal5 (49)</TD></TR> <TR><TD>ifName:</TD> <TD></TD></TR> <TR><TD>Max Speed:</TD> <TD>6144.0 kbits/s</TD></TR> <TR><TD>Ip:</TD> <TD>172.30.0.49 (serithc3602)</TD></TR> </TABLE><BR>


I think the result is in one line and I'm trying to put some needed data in one line as well (separated using commas):

System,Description,ifType,ifName,Max Speed,Ip

sERITHC3602,ATM2/0.4-aal5 layer VC link to sCRDONC3601 ATM2/0.1,aal5 (49),,6144.0 kbits/s,172.30.0.49 (serithc3602)

Just to grep the System data (sERITHC3602), I used this sed command:

MRTG$ grep -i "System" $file | sed 's/.*<System>\(.*\)<\/Maintainer>.*/\1/'

I used System and Maintainer strings because I know the data I need is between these two but I can still see the whole line after using sed.

Any help will be appreciated :)

Cheers!



 
Ooopss ... I forgot there is a small note that Feherke added in his posting ...

"The second solutions will not work well if there are input lines without that markup. Specify more about the input format if needed."

I will try a different approach ....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top