Bash 排序变量
我对变量排序有问题 我使用Bash和NSH控制台 我加载到操作系统中可变的最大文件夹:Bash 排序变量,bash,sorting,unix,Bash,Sorting,Unix,我对变量排序有问题 我使用Bash和NSH控制台 我加载到操作系统中可变的最大文件夹: vdirList=$(nexec -e "find /etc -type d -size +1k -print0 | xargs -0 du -h --max-depth 3 --time --time-style +'%F %T %z' 2>/dev/null| sort -h -k1 2>/dev/null| tail -7 | sed -n '$ ! p' | uniq -c | tac |
vdirList=$(nexec -e "find /etc -type d -size +1k -print0 | xargs -0 du -h --max-depth 3 --time --time-style +'%F %T %z' 2>/dev/null| sort -h -k1 2>/dev/null| tail -7 | sed -n '$ ! p' | uniq -c | tac | sed 's/^/BAORES: /'")
vdirList+="\n"
vdirList+=$(nexec -e "find /usr -type d -size +1k -print0 | xargs -0 du -h --max-depth 3 --time --time-style +'%F %T %z' 2>/dev/null| sort -h -k1 2>/dev/null| tail -7 | sed -n '$ ! p' | uniq -c | tac | sed 's/^/BAORES: /'")
vdirList+="\n"
这是输出:
BAORES: 3 22M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted
BAORES: 2 22M 2017-05-05 14:53:20 +0300 /etc/selinux
BAORES: 1 13M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted/modules
BAORES: 2 1.9G 2018-12-20 05:49:04 +0200 /usr/lib
BAORES: 3 1.3G 2018-12-20 05:48:55 +0200 /usr/lib/x86_64-linux-gnu
BAORES: 1 445M 2018-12-20 05:49:04 +0200 /usr/lib/i386-linux-gnu
我想按3列对文件进行排序我使用以下命令:
dirList=$(nexec -e "echo \"$vdirList\" | sort -hrk3 | head -n 10")
但我的输出是:
BAORES: 3 22M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted
BAORES: 3 1.3G 2018-12-20 05:48:55 +0200 /usr/lib/x86_64-linux-gnu
BAORES: 2 22M 2017-05-05 14:53:20 +0300 /etc/selinux
BAORES: 1 445M 2018-12-20 05:49:04 +0200 /usr/lib/i386-linux-gnu
BAORES: 1 13M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted/modules
BAORES: 2 1.9G 2018-12-20 05:49:04 +0200 /usr/lib
有人能帮忙吗?谢谢。我可以用
LC\u ALL=en\u US.UTF-8
确认这种奇怪的行为。在C语言环境下,它似乎工作正常:
$ input='BAORES: 3...
...
.../i386-linux-gnu'
$ LC_ALL=C sort -k3,3hr <<< "$input"
BAORES: 2 1.9G 2018-12-20 05:49:04 +0200 /usr/lib
BAORES: 3 1.3G 2018-12-20 05:48:55 +0200 /usr/lib/x86_64-linux-gnu
BAORES: 1 445M 2018-12-20 05:49:04 +0200 /usr/lib/i386-linux-gnu
BAORES: 2 22M 2017-05-05 14:53:20 +0300 /etc/selinux
BAORES: 3 22M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted
BAORES: 1 13M 2017-05-05 14:53:20 +0300 /etc/selinux/targeted/modules
但是我发现区域设置更可靠。是的,如果文件中有此输出,它可以工作,但我需要在变量中使用此。
LC_ALL=C sort-k3,3hr仍然是相同的输出:-/@destem:更新以准确显示对我有效的步骤。
sort -t' ' -k3,3hr