本帖最后由 haokoo 于 2014-02-27 15:58 编辑
RT 真的三言两语说不清,直接举个栗子:
file:- li,1038545726,manager,local account,,,cert,no,,
- ho,1029807038,manager,local account,,,cert,no,,
- cu,1073895116,manager,local account,,,cert,no,,
- lu,1166270565,manager,local account,,,cert,no,,
复制代码 将第二列的数值转化为16进制,并且进行排序,即:1038545726 --> 3DE6F33E --> 3EF3E63D
确认第二列的数值转化为16进制之后永远是固定8个字符的长度。
输出结果:- li,3EF3E63D,manager,local account,,,cert,no,,
- ho,BE9B613D,manager,local account,,,cert,no,,
- cu,CC560240,manager,local account,,,cert,no,,
- lu,65E08345,manager,local account,,,cert,no,,
复制代码 我写了很复杂的脚本,请各位帮忙简化简化,谢谢。- awk -F "," -v OFS="," '{cmd="echo \042ibase=10;obase=16;"$2"\042 | bc";cmd | getline n;cmd="echo "n" | sed -r \047s/(..)(..)(..)(..)/\\4\\3\\2\\1/g\047" ;cmd|getline n2;$2=n2;print $0}' file
复制代码 |