我有以下输出:
aaa=12
bbb=124
cccc=1
dddd=15
我想根据 value.s 对上面的行进行排序,因此输出应该如下所示:
$ cat file | awk_or_sed_or_any_command
cccc=1
aaa=12
dddd=15
bbb=124
更新
我尝试了以下命令:
$ cat file | awk -F '=' '{print $2"="$1}' | sort | awk -F '=' '{print $2"="$1}'
但是太长了。
还有比上述更好的建议吗?
注意:我的 linux 使用仅支持以下选项的 busybox 排序:
$ sort --help
BusyBox v1.19.4 (2014-04-04 18:50:39 CEST) multi-call binary.
Usage: sort [-nru] [FILE]...
Sort lines of text
-n Sort numbers
-r Reverse sort order
-u Suppress duplicate lines
最佳答案
使用以下命令
sort -n -t = -k 2 your_file
给我
alex@rhyme ~ $ ash
$ cat <<EOF | sort -n -t = -k 2
> aaa=12
> bbb=124
> cccc=1
> dddd=15
> EOF
cccc=1
aaa=12
dddd=15
bbb=124
$ which sort
/usr/bin/sort
$ LANG=C sort --version
sort (GNU coreutils) 8.21
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and Paul Eggert.
检查 sort manpage对于其他 sort
选项
关于linux - 如何根据行中的子字符串对行进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23516245/