The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Emergency UNIX and Linux Support !! Help Me!!
.
google unix.com



Emergency UNIX and Linux Support !! Help Me!! Post your urgent questions here for highest visibility. Posting a new thread to this forum requires Bits. We monitor this forum to help people with emergencies, but we do not guarantee response time or answers. This forum is "best effort" only. Members who reply to posts here receive a bonus of 1000 Bits per reply.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
searching for a string in a file ROOZ UNIX for Dummies Questions & Answers 2 03-07-2008 01:54 PM
Searching for a string variable mattrix UNIX for Dummies Questions & Answers 2 03-04-2008 04:04 PM
Extracting a string from one file and searching the same string in other files mohancrr Shell Programming and Scripting 1 09-19-2007 03:17 AM
one more query for searching string....... swamymns Shell Programming and Scripting 6 02-03-2006 08:57 AM
Searching a string for a character turbulence Shell Programming and Scripting 7 01-12-2006 09:56 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-2009
Mr. Zer0 Mr. Zer0 is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 9
TCL scripting - searching for a IP address in a string

Hi All,

Can anyone please help me with the regular expression/code snippet to search for an IP address in a string with Tcl scripting.

Example string
"OSPF_NBRUP OSPF neighbor 16.138.181.15 (realm ospf-v2 e1-0/0/0:37.0 area 0.0.0.0) state changed from Full to Down due to KillNbr"

In the above string i want to find IP 16.138.181.15



  #2 (permalink)  
Old 10-06-2009
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Something like this:

Code:
#!/usr/bin/tclsh 

set string "OSPF_NBRUP OSPF neighbor 16.138.181.15 (realm ospf-v2 e1-0/0/0:37.0 area 0.0.0.0) state changed from Full to Down due to KillNbr"

regexp {(?:\d+\.){3}\d+} $string matched

puts "matched is $matched"
It produces the following output:
Code:
% ./s  
matched is 16.138.181.15
Bits Awarded / Charged to radoulov for this Post
Date User Comment Amount
10-07-2009 frank_rizzo N/A 50,000
  #3 (permalink)  
Old 2 Weeks Ago
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
what does the below mean ... I am new in TCL and hope to benefit from this ...


Code:
{(?:\d+\.){3}\d+}


---------- Post updated at 07:26 AM ---------- Previous update was at 07:25 AM ----------

and is "puts" a command or just a word?
  #4 (permalink)  
Old 2 Weeks Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by ahmad.diab View Post
what does the below mean
[...]
Code:
{(?:\d+\.){3}\d+}



It's a regular expression that matches a sequence of 3 atoms of
one or more digit(s) followed by a literal dot[1] followed by one or more digit(s).


Quote:
[...]
Quote:
and is "puts" a command or just a word?
puts is a command.


[1]

Quote:
(?:.RE-a.) -- This modified version of grouping treats the enclosed regular expression atoms as an entity, but does not return the results in a match variable.
  #5 (permalink)  
Old 2 Weeks Ago
ahmad.diab's Avatar
ahmad.diab ahmad.diab is offline
Registered User
  
 

Join Date: May 2008
Location: Amman Jordan in MEA
Posts: 228
Thanks man
BR

One more thing ..can you please recommend to me some books related to TCL & TK

---------- Post updated at 07:01 AM ---------- Previous update was at 06:58 AM ----------

Quote:
Originally Posted by ahmad.diab View Post
Thanks man
BR
Quote:
One more thing ..can you please recommend to me some books related to TCL & TK

Thanks in advance
  #6 (permalink)  
Old 2 Weeks Ago
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Quote:
Originally Posted by ahmad.diab View Post
One more thing ..can you please recommend to me some books related to TCL & TK
I'm quite new to TCL too. I want to learn the language because of expect, which seems very interesting to me.
I purchased Exploring Expect on amazon and there is a quick TCL tutorial at the beginning of the book.
You could even consult it online on Google books.

I should add that the TCL group on USENET (comp.lang.tcl) is also a great resource.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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:33 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