TCL定制排序
由于我是 TCL 的新手,因此我将不胜感激。我通过对 CLI 命令的输出执行 'regexp -all -line -inline' + 标准来创建字符串列表。现在,此列表的每个元素都以数字结尾,我想按每个字符串结尾的特定数字对列表进行排序,但保留字符串的其余部分。一个类似的例子是必须按文件大小对“ls -la
”命令的输出进行排序。我尝试了以下方法,但没有成功:
lsort -command "regexp -lineanchor {\d+$}" -integer $list
花了一天时间试图解决这个问题后,我决定问你们。你能帮忙吗?
I would appreciate any help on this as I am new to TCL. I created a list of strings by doing a 'regexp -all -line -inline' + criterion on the output of a CLI command. Each element of this list now ends with a number and I want to sort the list on this particular numeric ending in each string but preserve the rest of the string. A close example would be to have to sort the output of the 'ls -la
' command by the size of the files. I tried the following but it did not work:
lsort -command "regexp -lineanchor {\d+$}" -integer $list
After spending a day on trying to figure this out I decided to ask you guys. Would you be able to help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老实说,我不明白你想用
-command "regexp -lineanchor {\d+$}"
实现什么目的。如果您打算比较数字,命令 regexp -lineanchor {\d+$} 实际上应该始终返回 1。如果您想按子列表的最后一个元素对列表进行排序,可以使用
-index
选项。例如:返回:
如果子列表中没有数据,但逐行有数据,则必须先
分割
它,例如:To be honest, I don't understand what you want to achieve with
-command "regexp -lineanchor {\d+$}"
. The commandregexp -lineanchor {\d+$}
should actually always return 1 if you plan to compare numbers.If you want to sort a list by the last element of its sublists you can use the
-index
option. E.g.:returns:
If you don't have your data in sublists but have the data line by line you have to
split
it before, e.g.: