使用 Unix 排序对多个键进行排序 [英] Sorting multiple keys with Unix sort

查看:33
本文介绍了使用 Unix 排序对多个键进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可能需要按 1-n 个键排序的大文件.其中一些键可能是数字,而其中一些可能不是.这是一个固定宽度的柱状文件,因此没有分隔符.

I have potentially large files that need to be sorted by 1-n keys. Some of these keys might be numeric and some of them might not be. This is a fixed-width columnar file so there are no delimiters.

是否有使用 Unix 排序的好方法?一键操作就像使用-n"一样简单.我已经阅读了手册页并简要搜索了谷歌,但没有找到一个很好的例子.我将如何完成这项工作?

Is there a good way to do this with Unix sort? With one key it is as simple as using '-n'. I have read the man page and searched Google briefly, but didn't find a good example. How would I go about accomplishing this?

注意:由于文件大小的潜力,我已经排除了 Perl.这将是最后的手段.

Note: I have ruled out Perl because of the file size potential. It would be a last resort.

推荐答案

使用 -k 选项(或 --key=POS1[,POS2]).它可以出现多次并且每个键可以有全局选项(例如n 用于数字排序)

Use the -k option (or --key=POS1[,POS2]). It can appear multiple times and each key can have global options (such as n for numeric sort)

这篇关于使用 Unix 排序对多个键进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆