Help using regexp in a TCL script ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help using regexp in a TCL script ??
# 1  
Old 09-25-2014
Question Help using regexp in a TCL script ??

In a tcl script I need to find a way of reading a file, and looking for a phrase ("set myvariable") and putting the word following that into a variable.
I've used a file open, and a while loop with gets to read each line from the file into a variable, and using regexp searched for the item. I'm struggling how to specify and isolate the word following the match and then to put it into a variable.
Code:
set fd [open $target_name.tcl r]
while {[gets $fd lib_str] >= 0} {
  if {[regexp -nocase {\mset\W\mmyvariable\W} $lib_str match]} { 
  puts stdout $match
  }
}

This works in that it finds and prints set myvariable. Smilie?
# 2  
Old 09-25-2014
Try this:

Code:
set fd [open $target_name.tcl r]
while {[gets $fd lib_str] >= 0} {
  if {[regexp -nocase {\mset\s+(myvariable)\s+(.+)$} $lib_str match var value]} { 
    puts stdout $match
    puts stdout $var
    puts stdout $value
  }
}


Last edited by Chubler_XL; 09-25-2014 at 06:30 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

TCL script to delete a pattern(regexp)

Hi I am writing a TCL script to delete a certain in a file My Input file module bist_logic_inst(a, ab , dhd, dhdh , djdj, hdh, djjd, jdj, dhd, dhp, dk ); input a; input ab; input dhd; input djdj; input dhd; output hdh; output djjd; output jdj; output dk; (1 Reply)
Discussion started by: kshitij
1 Replies

2. Shell Programming and Scripting

TCL script help

Hi All , I am having a file as stated below File 1 chain = chan6 group = grp0 input = '/pad_pc10' output = '/pad_pb7' length = 9900 chain = chan2 group = grp0 input = '/pad_pa4' output = '/pad_pb12' length = 10000 chain = chan7 group = grp0 input = '/pad_pb2' output =... (1 Reply)
Discussion started by: kshitij
1 Replies

3. Shell Programming and Scripting

Regexp in tcl

I need to change R3.1.5 as 03015 similarly R4.1.7 as 04017 i need a single command in tcl pls help ---------- Post updated at 05:19 PM ---------- Previous update was at 04:48 PM ---------- i had to do like this without using regexp set old_release "R3.1.5" ... (1 Reply)
Discussion started by: Syed Imran
1 Replies

4. Shell Programming and Scripting

Question on regexp in TCL

I need some help with regexp in tcl. The following code does work if the $urlvar ends in jpg,jpeg,png or gif. Eg, protocol(http/https)://testsite.com/images/image1.jpg if { ! } { //Do something } My problem is that if the URL does not end in these extensions this regexp is of no... (1 Reply)
Discussion started by: ampak
1 Replies

5. Shell Programming and Scripting

Question on TCL regexp and match

Hello everyone, I'm new in tcl scripting. I'm currently studying a tcl script and came across this line: regexp {(\d+)(\S?)} $opts match opt swi According to my understanding, this line means to search in the opts variable for one or more digit, followed by a non-whitespace character... (2 Replies)
Discussion started by: mar85
2 Replies

6. Programming

Tcl script

Dear Users I'm struck by while the following tcl script. foreach l { set w($l) {} set fsum 0 foreach ftemp $f($l) { set fsum lappend w($l) $fsum } } It shows me error as "missing operand at _@_ in expression "0.10308400000000001 + _@_* 0.4 * 1" ... (0 Replies)
Discussion started by: bala06
0 Replies

7. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

8. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

9. Shell Programming and Scripting

Passing a regexp to grep via a shell script

Hello, I have the output of ls -l stored in a text file called "files.txt". -rwx------ 1 user1 dev 130 Sep 21 16:14 sc1.sh -rwxr----- 1 user1 dev 10328 Sep 29 20:11 sc10.sh -rwxr----- 1 user1 dev 9984 Sep 30 15:33 sc11.sh -rwxr----- 1 user1 dev ... (2 Replies)
Discussion started by: rogersed
2 Replies

10. Shell Programming and Scripting

tcl: regexp matching special character

Hello Experts, Can someone help me here: I have a variable which contains a string with "". set var1 {a} set str1 {a is the element i want to match} Now "regexp $var1 $str1" does not work? ("regexp {a\} $str1" works, but var1 gets it's value automatically from another script) Is... (6 Replies)
Discussion started by: sumitgarg
6 Replies
Login or Register to Ask a Question