对一些查找结果进行排序
我需要对 HP-UX 上的查找输出进行排序。我得到以下结果:
/path/to/folder/one/blabla_110303121212.x
/path/to/folder/two/otherblabla_1102124302.x
etc.
使用 sort -t"\" -k5,我设法从最后一个 / 排序,但现在我希望能够仅从数字套装上的最后一个下划线排序。 -t 不能使用两个分隔符(唉),-n 不起作用(不知道为什么),我无法给出确切的数字来告诉 -k 第二个参数,因为 " 的大小,键从哪里开始blabla”永远不会一样,我需要保留这些(诚然烦人的)路径。
有人知道吗?提前致谢 !
I need to sort the output of a find on a HP-UX. I've got the following results :
/path/to/folder/one/blabla_110303121212.x
/path/to/folder/two/otherblabla_1102124302.x
etc.
With sort -t"\" -k5, I managed to sort from the last /, but now I want to be able to sort from only the last underscore, on the numerical suit. -t can't take two separators (alas), -n didn't work (don't know why), I can't give an exact number to tell with -k second argument where the key starts since the size of "blabla" is never the same, and I need to keep those (admittedly annoying) paths.
Does anyone have any idea ? Thanks in advance !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sort(1)
通常是稳定的,这意味着如果元素具有相同的排序键,它不会扰乱元素的顺序。所以解决办法就是对输出进行多次排序;从下划线后面的部分开始,然后按名称排序。
另一种解决方案是将文件切成列,更改列的顺序,对此中间文件进行排序,然后将列连接回原始形式。
使用
awk(1)
,您可以创建This can be sorted without any options;只需在前缀和后缀之间添加足够的空格并将后缀向右对齐即可。
sort(1)
is usually stable which means that it won't disturb the order of elements if they have the same sort key.So the solution is to sort the output several times; start with the parts after the underscore and then sort for name.
Another solution is to cut the file into columns, change the order of the columns, sort this intermediate file, and then join the columns back into the original form.
With
awk(1)
, you could createThis can be sorted without any options; just add enough whitespace between the prefix and the suffix and align the suffix to the right.