TCL Script Regular expression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TCL Script Regular expression
# 1  
Old 03-09-2011
Data TCL Script Regular expression

Hi ,
I'm working on tcl script to extract specific data . I tried to use regular expression (new to regular expression) but I couldn't get it.

here is a smaple of what I'm trying to extract from:
Code:
+ 20.167 0 1 cbr 500 ------- 2 5.0 1.3 3091 57612
d 20.167 0 1 cbr 500 ------- 2 5.0 1.3 3091 57612
r 20.167 6 0 cbr 500 ------- 2 6.0 1.4 3071 57613
+ 20.167 0 1 cbr 500 ------- 2 6.0 1.4 3071 57613
d 20.167 0 1 cbr 500 ------- 2 6.0 1.4 3071 57613

I used the following expression to extract the lines with the following information:

"d" && 0 & 1 (note "0" is the 3rd col and "1" the 4th )

My logic based on reading line by line and perform specific conditons. each line should have "d" & "0" &"1".

here is my try:
Code:
if [regexp {\"d" ([0-9.]+) 0 1.*- ([0-9]+) } $line -> time flowid] {

this condtion giving me empty output.


Any Help?


Regards,
Moe
# 2  
Old 03-09-2011
Hi.

This seems to work:
Code:
#!/usr/bin/env tclsh

# @(#) tcl1     Demonstrate tclsh regexp.

puts stdout ""

set version [ info tclversion ]
set message " Version ($version)"
puts stdout $message

puts stdout ""

set channel {stdin}

while { [ gets $channel line ] > 0 } {
  set m " Processing line \[$line\]"
  puts $m
  if { [ regexp {d ([0-9.]+) 0 1.*- ([0-9]+) } $line ] } {
    puts " Hit!"
  } else {
    puts " No hit."
  }
}

exit 0

producing:
Code:
./tcl1 < data1

 Version (8.4)

 Processing line [+ 20.167 0 1 cbr 500 ------- 2 5.0 1.3 3091 57612]
 No hit.
 Processing line [d 20.167 0 1 cbr 500 ------- 2 5.0 1.3 3091 57612]
 Hit!
 Processing line [r 20.167 6 0 cbr 500 ------- 2 6.0 1.4 3071 57613]
 No hit.
 Processing line [+ 20.167 0 1 cbr 500 ------- 2 6.0 1.4 3071 57613]
 No hit.
 Processing line [d 20.167 0 1 cbr 500 ------- 2 6.0 1.4 3071 57613]
 Hit!
 Processing line [d 20.167 2 1 cbr 500 ------- 2 6.0 1.4 3071 57613]
 No hit.
 Processing line [d 20.167 0 3 cbr 500 ------- 2 6.0 1.4 3071 57613]
 No hit.

Best wishes ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with Regular expression in ping script

Hi everyone, ping www.google.com | awk 'BEGIN{FS="+";}{if ($10 ~ (/^$/) || (/^\.?/)) print "SLOW"; else print $0} output awk: warning: escape sequence `\=' treated as plain `=' PING www.google.com (xxx.xxx.xxx.xxx) 56(84) bytes of data. 64 bytes from xxx.xxx.xxx.xxx icmp_req=2 ttl=128... (3 Replies)
Discussion started by: Apollo
3 Replies

2. Shell Programming and Scripting

Help with awk script (syntax error in regular expression)

I've found this script which seems very promising to solve my issue: To search and replace many different database passwords in many different (.php, .pl, .cgi, etc.) files across my filesystem. The passwords may or may not be contained within quotes, single quotes, etc. #!/bin/bash... (4 Replies)
Discussion started by: spacegoose
4 Replies

3. Shell Programming and Scripting

incorporating a regular expression statement in a shell script (.sh)

I do have a shell file where I call many unix commands . I would like to add a regular expression step in that shell file, where a text file, say Test.txt has to be openned and all the :'s should be replaced. Basically apply the follwoing regular expression: :%s/://g to that particular text... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

4. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

5. Shell Programming and Scripting

regular expression with shell script to extract data out of a text file

hi i am trying to extract some specific data out of a text file using regular expressions with shell script that is using a multiline grep .. and the tool i am using is pcregrep so that i can get compatibility with perl's regular expressions for a sample data like this, i am trying to grab... (6 Replies)
Discussion started by: vemkiran
6 Replies

6. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

7. Shell Programming and Scripting

AWK Script Issue insert newline for a regular expression match

Hi , I am having an issue with the Awk script to insert newline for a regular expression match Having a file like this FILE1 #################### RXOER , RXERA , RXERC , RXERD .RXEA(RXBSN), RXERD , REXCD input RXEGT buffer RXETRY ####################### Want to match the RXE... (38 Replies)
Discussion started by: jaita
38 Replies

8. Shell Programming and Scripting

AWK script issue for the part regular expression

Hi I am having a file as shown below FILE 1 TXDD00, TXDD01, TXDD02, TXDD03, TXDD04, TXDD05, TXDD06, TXDD07, TXDD08, TXDD09, TXDD10, TXDD11, TXDD12, TXDD13, TXDD14, TXDD15, TXDD16, TXDD17, TXDD18, TXDD19, TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1,... (3 Replies)
Discussion started by: jaita
3 Replies

9. Shell Programming and Scripting

problem with Regular expression as input in shell script

Hi, I have script which will take a string as input and search in a file. But when I want to search a pattern which has special characters script is ignoring it. For example: I want to search a pattern "\.tumblr\.com". shell script is removing \ (backslah) and trying to search... (7 Replies)
Discussion started by: Anjan1
7 Replies

10. Shell Programming and Scripting

using regular expression an shell script!!

I want to check if the first argument of my shell script starts with a specifiec string? Any Idea?? Thank u (3 Replies)
Discussion started by: andy2000
3 Replies
Login or Register to Ask a Question