0
set_dont_use [get_lib_cells */*CKGT*0P*] -power
set_dont_use [get_lib_cells */*CKTT*0P*] -setup

The above is a text file.

I Want to store */CKGTOP* and */CKTTOP* in to a variable this is the programme which a person helped me with

set f [open theScript.tcl]
# Even with 10 million lines, modern computers will chew through it rapidly
set lines [split [read $f] "\n"]
close $f

# This RE will match the sample lines you've told us about; it might need tuning
# for other inputs (and knowing what's best is part of the art of RE writing)
set RE {^set_dont_use \[get_lib_cells ([\w*/]+)\] -\w+$}

foreach line $lines {
    if {[regexp $RE $line -> term]} {
        # At this point, the part you want is assigned to $term
        puts "FOUND: $term"
    }
}

My question is if more than one cells like for example

set_dont_use [get_lib_cells */*CKGT*0P* */*CKOU*TR* /*....] -power
set_dont_use [get_lib_cells */*CKGT*WP* */*CKOU*LR* /*....] -setup

then the above script isn't helping me to store the these "n" number cells in the variable known as term

Could any of u people help me Thanking you ahead in time

  • Possible duplicate of [How to grep parameters inside square brackets?](http://stackoverflow.com/questions/42143073/how-to-grep-parameters-inside-square-brackets) – mkrieger1 Feb 11 '17 at 14:40
  • This is the same question you have asked already. If you want to clarify something, you can edit the original question. – mkrieger1 Feb 11 '17 at 14:41

2 Answers2

1

I would go with

proc get_lib_cells args {
    global term
    lappend term {*}$args
}

proc unknown args {}

and then just

source theScript.tcl

in a shell that doesn't have the module you are using loaded, and thus doesn't know any of these non-standard commands.

By setting unknown to do nothing, other commands in the script will just be passed over.

Note that redefining unknownimpairs Tcl's ability to automatically load some processes, so don't keep using that interpreter after this.

Documentation: global, lappend, proc, unknown, {*} (syntax)

Peter Lewerin
  • 13,140
  • 1
  • 24
  • 27
0

Your coding seems like the Synopsys syntax, meaning - it shouldn't work the way you wrote it, I'd expect curly braces:
set_dont_use [get_lib_cells {*/*CKGT*0P* */*CKOU*TR* /*....}] -power
moreover, the \w doesn't catch the *,/ (see this).
If I were you, I'd go for set RE {^set_dont_use \[get_lib_cells \{?([\S*]+ )+\}?\] -\w+$} and treat the resulting pattern match as a list.

Edit:
see this:
% regexp {^set_dont_use [get_lib_cells {?(\S+) ?}?]} $line -> match
1
% echo $match
*/*CKGT*0P*
If you have more than one item in your line, add another parentheses inside the curly braces:
regexp {^set_dont_use \[get_lib_cells \{?(\S+) ?(\S+)?\}?\]} $l -> m1 m2
ect.
Another Edit
take a look at this, just in case you want multiple matches with the same single pattern, but than, instead of \S+, you should try something that looks like this: [A-Za-z\/\*]

Community
  • 1
  • 1
user2141046
  • 862
  • 2
  • 7
  • 21
  • couldn't compile regular expression pattern: invalid escape \ sequence while executing "regexp $RE $line -> term" ("foreach" body line 2) invoked from within "foreach line $lines { if {[regexp $RE $line -> term]} { # At this point, the part you want is assigned to $term puts "FOUND: $term" ..." (file "con.tcl" line 10) This is the following error i am getting while excecuting the sciprt given by u – Karthik Kumar Feb 20 '17 at 06:25
  • here the number of cells is defined by the tool, suppose we have more than 1K cells it will be practically impossible to keep adding parentheses rit please correct me if i am wrong – Karthik Kumar Feb 20 '17 at 09:54