TCL script to print range of lines between patterns


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers TCL script to print range of lines between patterns
# 1  
TCL script to print range of lines between patterns

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;
endmodule

I need to match the string between "input" and ";" create a list similarly need to match the string between "output" and ";" create a list

My Input list should be

Code:
a , b,   da , fa ,na , ta , ma

Output list should be

Code:
c , ra ,ta ,la , pa



I have tried below code but not getting the desired outcome

Code:
set chan [open "mod1.v"]
set out [open "output.file.txt" "w"]
set lineNumber 0
# Read until we find the start pattern
while {[gets $chan line] >= 0} {
    incr lineNumber
   puts $line
    if { [string match "input" $line]} {
        # Now read until we find the stop pattern
        while {[gets $chan line] >= 0} {
            incr lineNumber
            if { [string match ";" $line] } {
                close $out
                break
            } else {
                puts $out $line
            }
        }
    }
}
close $chan



Expected results

My Input list should be

Code:
a , b,   da , fa ,na , ta , ma
Output list should be


Code:
c , ra ,ta ,la , pa

# 2  
Try this:

Code:
set chan [open "mod1.v"]
set out [open "output.file.txt" "w"]
set lineNumber 0
# Read until we find the start pattern
while {[gets $chan line] >= 0} {
   incr lineNumber
   puts $line
    if { [string match "input*" $line]} {
        # Now read until we find the stop pattern
        while {[gets $chan line] >= 0} {
            incr lineNumber
            # get rid of spaces at front
            regsub {^ *} $line "" line
            # get rid of "output"
            regsub {^output} $line "" line
            if { [string match "*;" $line] } {
                regsub {;.*} $line "" line
                puts $out $line
                close $out
                break
            }
            puts -nonewline $out $line
        }
    }
}
close $chan

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 #783
Difficulty: Medium
Microsoft launched its first retail version of Microsoft Windows in 1983.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

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

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; // MBIST Structures... (1 Reply)
Discussion started by: kshitij
1 Replies

2. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

3. Shell Programming and Scripting

Perl : to print the lines between two patterns

Hello experts, I have a text file from which I need to print all the lines between the patterns. Could anyone please help me with the perl script. names.txt ========= Badger Bald Eagle Bandicoot Bangle Tiger Barnacle Barracuda Basilisk Bass Basset Hound Beetle Beluga... (7 Replies)
Discussion started by: scriptscript
7 Replies

4. Shell Programming and Scripting

Print all lines between patterns

Hi Gurus, I have a requirement where I need to display all lines between 2 patterns except the line where the first pattern in it. I tried the following command using awk but it is printing all lines except the lines where the 2 patterns exist. awk '/TRANSF_/{ P=1; next } /Busy/ {exit} P'... (9 Replies)
Discussion started by: svajhala
9 Replies

5. Shell Programming and Scripting

How to print only lines in between patterns?

Hi, I want to print only lines (green-italic lines) in between first and last strings in column 9. there are different number of lines between each strings. 10 AUGUSTUS exon 4558 4669 . - . 10.g1 10 AUGUSTUS exon 8771 8889 . ... (6 Replies)
Discussion started by: jamo
6 Replies

6. Shell Programming and Scripting

Need to print between patterns AND a few lines before

I need to print out sections (varying numbers of lines) of a file between patterns. That alone is easy enough: sed -n '/START/,/STOP/' I also need the 3 lines BEFORE the start pattern. That alone is easy enough: grep -B3 START But I can't seem to combine the two so that I get everything between the... (2 Replies)
Discussion started by: Finja
2 Replies

7. Shell Programming and Scripting

print lines between 2 matching patterns

Hi Guys, I have file like below, I want to print all lines between test1231233 to its 10 occurrence(till line 41) test1231233 qwe qwe qweq123 test1231233 qwe qwe qweq23 test1231233 qwe qwe qweq123 test1231233 qwe qwe qweq123131 (3 Replies)
Discussion started by: jagnikam
3 Replies

8. Shell Programming and Scripting

Print lines between two repetitive patterns

Hi users I have one file which has number of occurrence of one pattern examples Adjustmenttype,11 xyz 10 dwe 9 abd 13 def 14 Adjustmenttype,11 xyz 24 dwe 34 abd 35 def 11 nmb 12 Adjustmenttype, not eleven .... ... ... (2 Replies)
Discussion started by: eranmoh
2 Replies

9. Shell Programming and Scripting

print lines between two patterns in unix

Detroit Chicago Newyork Battlecreek Jackson Brooklyn How would I print only lines match between Detroit and Brooklyn used awk ? I don't want print Detroit and Brooklyn output should be : Chicago Newyork Battlecreek Jackson Thanks Jhonny (2 Replies)
Discussion started by: jhonnyrip
2 Replies

10. Shell Programming and Scripting

print range between two patterns if it contains a pattern within the range

I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated. e.g. Pattern1 Bombay Calcutta Delhi Pattern2 Pattern1 Patna Madras Gwalior Delhi Pattern2 Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies

Featured Tech Videos