tcl脚本读写操作

open filename access

#access 包括r, w, a, r+, w+, a+ read -nonewhile $fp
#读取并返回文件剩余的所有内容 puts -nonewhile $fp str
#将字符串str写入到标识符为fp的文件中, 如果不加-nonewhile, 则str末尾会加换行符

set fp1 [open "file1.txt" "w"]
puts $fp1 "Content: first line."
puts $fp1 "0x1002"
puts $fp1 "45671234"
puts -nonewline $fp1 "Content: end line"
close $fp1

下面是另一个例子读取文件,文件一行一行直到结束。

#!/usr/bin/tclsh

set fp [open "input.txt" w+]
puts $fp "test\ntest"
close $fp
set fp [open "input.txt" r]

while { [gets $fp data] >= 0 } {
   puts $data
}
close $fp

set y /u/home/tcl/list.tcl
split $y /
=> {} u home tcl list.tcl

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值