TCL script to capture range of lines and create two independent variables


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting TCL script to capture range of lines and create two independent variables
# 1  
TCL script to capture range of lines and create two independent variables

Hi I am having a code as stated below

Code:
module abcd( a , b , c ,da , fa, na , ta , ma , ra ,
              ta, la , pa );

input a , b, da ,fa , na , ta , ma; 
output c , ra ,ta , 
          la ,pa ;
wire a , b , da , fa ,na ,
        ta , ma;


// MBIST Structures
mbist_hsm_p::mbist_out_hsm_t         mbist_out_hsm;
mbist_hsm_p::mbist_in_hsm_t          mbist_in_hsm;

// HMS 
kkkks ;

jsskks;

endmodule


Need to take the range between "MBIST Structures " and "//" and the take the first line as a input variable and second line as a output variable.

For example , I am trying below stated code


Code:
proc findrange {data start {stop ;}} {
    # Find the starting pattern
    set x1 [string first $start $data]
    if {$x1 < 0} {
        # Pattern not found
        return
    }
    # Skip the pattern
    incr x1 [string length $start]
    # Find the ending pattern after the starting position
    set x2 [string first $stop $data $x1]
    if {$x2 < 0} {
        # Return the remainder of the data when no ending pattern is found
        return [string range $data $x1 end]
    } else {
        # Return the text between the starting and ending patterns
        return [string range $data $x1 [expr {$x2 - 1}]]
    }
}


set chan [open "mode.v"]
set code [read $chan]
close $chan

set var4 [ findrange $code "MBIST Structures" \/\/]


echo $var4 is printing these variables

Code:
mbist_hsm_p::mbist_out_hsm_t         mbist_out_hsm;
mbist_hsm_p::mbist_in_hsm_t          mbist_in_hsm;

```
I want to have two lists

Code:
$input should be "mbist_hsm_p::mbist_out_hsm_t         mbist_out_hsm;"
$output should be "mbist_hsm_p::mbist_in_hsm_t          mbist_in_hsm;"

How to create these variables from the var4 variable

When I am trying out to print out the $var4 variable , it is printing 4 independent variables


Code:
foreach p $var4 {
echo $p
}



mbist_hsm_p::mbist_out_hsm_t
mbist_out_hsm;
mbist_hsm_p::mbist_in_hsm_t
mbist_in_hsm;


Code:
Rather it should be " mbist_hsm_p::mbist_out_hsm_t mbist_out_hsm;"
and other one should be "mbist_hsm_p::mbist_in_hsm_t mbist_in_hsm;"

Two lists I am looking for
$input and $output
# 2  
You could split on newline before doing a foreach like this:

Code:
foreach p [ split $var4 "\n" ] {
   puts $p
}

This User Gave Thanks to Chubler_XL For This Post:
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #491
Difficulty: Easy
In general, interpreted languages are slower than compiled languages.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

TCL script to extract the file name and then create two independent list

I am having one problem as stated below Problem Description I am having some "sv" extension files , I am using "glob" to extract the matching files , Now in these matching files , I need to split them and extract the elements and create different lists. For example set files This... (1 Reply)
Discussion started by: kshitij
1 Replies

2. UNIX for Beginners Questions & Answers

TCL script to print range of lines between patterns

Hi I am having a code as stated below module abcd( a , b , c ,da , fa, na , ta , ma , ra , ta, la , pa ); input a , b, da ,fa , na , ta , ma; output c , ra ,ta , la ,pa ; wire a , b , da , fa ,na , ta , ma; endmodule I need to match the string... (1 Reply)
Discussion started by: kshitij
1 Replies

3. Shell Programming and Scripting

Dialog , capture multiples inputs in variables

Hi everyone , i am trying to do a shell script with dialog , but i have a problem capturing each input variable to then use "echo" to write those inputs on specific orders in a file . If i use this code : dialog --backtitle "Dialog Form Example" --title "Dialog - Form" \ --form "\nDialog... (1 Reply)
Discussion started by: pedropt
1 Replies

4. Shell Programming and Scripting

awk to create variables to pass into a bash loop to create a download link

I have created one file that contains all the necessary info in it to create a download link. In each of the lines /results/analysis/output/Home/Auto_user_S5-00580-6-Medexome_67_032/plugin_out/FileExporter_out.67... (8 Replies)
Discussion started by: cmccabe
8 Replies

5. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

6. Shell Programming and Scripting

Bash script - printing range of lines from text file

I'm working on a new exercise that calls for a script that will take in two arguments on the command line (representing the range of line numbers) and will subsequently print those lines from a a specified file. Command line would look like this: ./lines_script.bash 5 15 <file.txt. The script would... (8 Replies)
Discussion started by: ksmarine1980
8 Replies

7. Shell Programming and Scripting

Wrap lines with awk to create SQL script

Greetings! Some of my files list hardware errors (we test electronic components), some have none. If the file name has no errors, I still want to display a message like "No error", else I display the error from the file itself. I came up with this (with help) for myfile in `find . -name... (2 Replies)
Discussion started by: alan
2 Replies

8. Shell Programming and Scripting

how to create and access a directory in the same script using variables

I have a working script that defines the paths using variables which is used to move a rename files that are being archived. Is there a way to create a directory in the path with the date as the name and then reference it when moving the file to it? Here is what I have tried with no luck.... ... (1 Reply)
Discussion started by: Snickyt0310
1 Replies

9. Shell Programming and Scripting

Script to capture new lines in a file and copy it to new file

Hi All, I have a file that gives me new line/output every 5 minutes. I need to create a script that capture new line/output besides "IN CRON_STATUS", in this case the new output is "begin ------ cron_status.sh - -----------". I want this script to capture the line starting from "begin ------... (0 Replies)
Discussion started by: fara_aris
0 Replies

10. UNIX Desktop Questions & Answers

trying to create a script with multiple variables...

I have created a script that prompts the user to enter three variables that are seperated by a space as the delimiter. It then performs a command 3 seperate times for each variable entered. I want the script to llow the user to enter as many variables as they may like and the script to... (5 Replies)
Discussion started by: Italy87
5 Replies

Featured Tech Videos