TCL脚本重组CSV文件数据
我是TCL脚本的新手。
我的CSV文件中有2列。
示例:我的数据
A 12
D 18
B 33
A 11
D 49
我想使用第1列数据提取2列值。
所需的输出:
A: 12,11
B: 33
D: 18, 49
有人可以帮助我编写TCL脚本以执行此任务吗? 先感谢您。
I am new to tcl scripting.
I have 2 columns in my CSV file.
Example: My data
A 12
D 18
B 33
A 11
D 49
I would like to extract column 2 values using Column 1 data.
Required output:
A: 12,11
B: 33
D: 18, 49
Can someone please help me to write a tcl script to perform this task?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个众所周知的问题,TCL的
dict lappend
正是您需要解决的工具(与csv :: Split
从TCLLIB一起进行解析输入数据)。以上写为stdin到stdout滤镜。适应与文件一起工作是作为练习。
This is a very well known problem, and Tcl's
dict lappend
is exactly the tool you need to solve it (together withcsv::split
from tcllib to do the parsing of your input data).The above is written as a stdin-to-stdout filter. Adapting to work with files is left as an exercise.