top of page
Admin

Reading a csv file by using tcl

Reading a csv file procedure is similar to the other programming languages.


# Open the CSV file in read mode

set filePath "C:/Users/PC/Desktop/example.csv"

set fileId [open $filePath r]


# Read the file content

set fileData [read $fileId]

close $fileId


puts "File content:"

puts $fileData


# Split the file data into lines

set lines [split $fileData "\n"]


# Iterate over each line

foreach line $lines {


# Skip empty lines


if {$line eq ""} {


continue


}


# Split the line into fields by the delimiter (e.g., comma,semicolon, space)


set fields [split $line ","]


# Process the fields (e.g., print them)


puts "Line: $line"


puts "Fields: $fields"


}

Recent Posts

See All

Creating components with TCL in Hypermesh

For creating multiple components in HYPERMESH with TCL, you can use the code below. for {set i 1000} {$i <1250} {incr i} {*createentity...

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page