cancel
Showing results for 
Search instead for 
Did you mean: 

post how to read txt FIXED line

Pioneer
Pioneer
dear sir can you help me,if i want to read a txt, it is ok, i can do it, but how to read pointed lin, for example if how to read two line content thanks
8 REPLIES

Re: post how to read txt FIXED line

Legend
Legend

Show us your code to read a file ? And what do you want extract ?
There are several ways to read a text file and extract the data

@mkn
Production: NX11.0.2.7,VERICUT 7.3.3
Development: Tcl/Tk, Gnuplot
www.deshors-tiremold.com

Re: post how to read txt FIXED line

Pioneer
Pioneer

dear sir 

 

thanks your reply, i want to read extract line ,but can't find a way 

 

set a5 "C:/num.txt"
set b5 [open $a5 r]
set d6 [gets $b5]

MOM_output_text $d6

Re: post how to read txt FIXED line

Legend
Legend

You always not tell us what you want to extract as data.That said...

To begin... Smiley Wink

for read a file :

line by line :

set a5 "C:/num.txt"
set in [open $a5 r]

while {[gets $in line] != -1} {
    if {[string match {*what you're looking for...*} $line]} {
        MOM_output_literal $line ; # I don't know 'MOM_output_text'
    } else {
       MOM_output_literal "does not match case here..."
    }

}
close $in

more information about : string match...

another solution :

# list + foreach or lsearch...

set a5 "C:/num.txt"
set in [open $a5 r]
set fp [read $in] 
set l [split $fp "\n"]
close $in

foreach line $l {
# do something else
}

look this way if you want filter your list "$l" : lsearch...

Information : readforeachsplitopen , gets...

it is a good start for read a file in Tcl...

I hope this helps...

@mkn
Production: NX11.0.2.7,VERICUT 7.3.3
Development: Tcl/Tk, Gnuplot
www.deshors-tiremold.com

Re: post how to read txt FIXED line

Pioneer
Pioneer

so thanks it is very excited, it is powerful, yes i want to began learn tcl language,thanks so much again !

 

if i want to define a variable ,it use for read line ,how i can read pointed line content?

Re: post how to read txt FIXED line

Pioneer
Pioneer
for example in num.txt content
10
11
12
13
14

how to read fixed line content

Re: post how to read txt FIXED line

Pioneer
Pioneer

for example how to read variable point line 

in the num.txt content 

 

10

11

12

13

15

if i want to read second line content how to point a variable ?

Re: post how to read txt FIXED line

Esteemed Contributor
Esteemed Contributor

Go online & search for some tcl tutorials.

 

for MKN:

Main differencebetween MOM_output_literal & MOM_output_text is that MOM_output_literal will include the "block number " ("Nnnnn") at the beginning of t he line (assuming they are turned on) and MOM_output_text won't.

https://docs.plm.automation.siemens.com/tdoc/nx/11/nx_help#uid:xid1128418:index_xid917284:xid913731:...

 

Ken Akerboom Sr CAx Systems Engr, Moog, Inc.
Production: NX10.0.3.5 MP5 + patch/TC11.2
I'd rather be e-steemed than e-diseaseled


Re: post how to read txt FIXED line

Legend
Legend




for MKN:

Main differencebetween MOM_output_literal & MOM_output_text is that MOM_output_literal will include the "block number " ("Nnnnn") at the beginning of t he line (assuming they are turned on) and MOM_output_text won't.

https://docs.plm.automation.siemens.com/tdoc/nx/11/nx_help#uid:xid1128418:index_xid917284:xid913731:...

 



Thanks @Ken_A for this information.

@mkn
Production: NX11.0.2.7,VERICUT 7.3.3
Development: Tcl/Tk, Gnuplot
www.deshors-tiremold.com

Learn online





Solution Information