从命令行中排序不同长度的十六进制数? [英] sort hex numbers of different length from the command line?

查看:181
本文介绍了从命令行中排序不同长度的十六进制数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个不同长度的十六进制数文件,例如

  1F 
b
c

如何从命令行对它们进行排序?



<欢迎使用Linux解决方案,但我会使用windows和cygwin或gnuwin32。



注意:我显然不能使用SORT的cos,该命令是错误的。

解决方案

 同时读线; do printf%d%s\\\
0x $ line$ line;完成| sort -n | awk'{print $ 2}'

这将保留十六进制数的原始大小写。 / p>

If I have a file of hex numbers of different length e.g.

1F
b
c

How can I sort them from the command line?

Linux solutions are welcome, though I'll be using windows and cygwin or gnuwin32.

Note: I clearly can't use SORT 'cos that will keep them in that order which is wrong.

解决方案

cat thefile | while read line; do printf "%d %s\n" "0x$line" "$line"; done | sort -n | awk '{print $2}'

This retains the original upper/lower case of the hexadecimal numbers.

这篇关于从命令行中排序不同长度的十六进制数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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