LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-08-2012, 06:07 AM   #1
kamesp
LQ Newbie
 
Registered: Jun 2012
Posts: 10

Rep: Reputation: Disabled
How to match for a pattern in a string using tcl


Hi,

I need to match a particular pattern in the output of ifconfig command which i have written a code in tcl to match.I am getting an error near if condition and unable to proceed further.. Please help me in solving the same

#!/usr/bin/tclsh

set x " Link encap:Ethernet HWaddr 3C9:2B:09:76:54
inet addr:172.16.51.100 Bcast:172.16.51.127 Mask:255.255.255.128
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:383037553 errors:0 dropped:0 overruns:0 frame:0
TX packets:300897395 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4259153427 (4061.8 Mb) TX bytes:3588769001 (3422.5 Mb)
Interrupt:169 Memory:f4000000-f4012800"


set y [ split $x "\n" ]
puts [lindex $y]
puts [llength $y]
set index [ lindex $y 3]
puts [lindex $y 3]
if {[ regexp {frame} $index ] > 0 }
{
puts "The IP is pinging"
}
{
puts "The IP is not pinging"


Also let me know how can i write a code in TCL if i have a matrix as below

A B C D E
1 2 3 4 5
a b c d e

and if i need to search for the element 5 and if available print the corresponding all elements in the same row of 5.

Thanks in advance.
Kamesh
 
Old 06-08-2012, 04:58 PM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
This is probably a bit more like what you want.


Code:
#!/usr/bin/tclsh

set x " Link encap:Ethernet HWaddr 3C9:2B:09:76:54
inet addr:172.16.51.100 Bcast:172.16.51.127 Mask:255.255.255.128
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:383037553 errors:0 dropped:0 overruns:0 frame:0
TX packets:300897395 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4259153427 (4061.8 Mb) TX bytes:3588769001 (3422.5 Mb)
Interrupt:169 Memory:f4000000-f4012800"


set y [ split $x "\n" ]
puts [lindex $y]
puts [llength $y]
set index [ lindex $y 3]
puts [lindex $y 3]

if {[ regexp {frame} $index ] > 0 } \
{
    puts "The IP is pinging"
} \
else \
{
    puts "The IP is not pinging"
}
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
reg expr: match a string A-Z, a-z, * or a blank ( but string can not be all blanks) matt007 Programming 4 12-22-2009 08:55 AM
[SOLVED] Adding (not replacing) a pattern match with a similar pattern? b-bri Linux - Newbie 2 08-31-2009 12:36 AM
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
how to match for multiple pattern at the end of given string Santoshkb Programming 2 06-23-2008 10:42 AM
Rewrite rule with query string in the pattern string basahkuyup Linux - Newbie 2 10-17-2006 02:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration