linux - 我可以更改 Linux cut 命令的输出字段的顺序吗?

标签 linux bash shell awk cut

<分区>

我在命令行中使用 cut 命令,但似乎无法获得我喜欢的输出。 你知道我为什么会收到这个吗?是我做错了什么吗?

这是正常的输出,我想以不同的顺序输出:

[root@upbvm500 root]# ls -al IDS_DIR/a | tr -s " "
-rw-r--r-- 1 root root 0 Jan 1 17:18 IDS_DIR/a
[root@upbvm500 root]#

[root@upbvm500 root]# ls -al IDS_DIR/a | tr -s " " | cut -d" " -f5,6,7,8,3,4,1
-rw-r--r-- root root 0 Jan 1 17:18

但是如您所见,这并没有像预期的那样工作。 知道他们为什么要换地方吗?

最佳答案

来自 man cut:

Selected input is written in the same order that it is read, and is written exactly once.

使用 awk '{print $5,$6,$7,$8,$3,$4,$1}' 而不是 cut

关于linux - 我可以更改 Linux cut 命令的输出字段的顺序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14112120/

相关文章:

java - 如何在每个 json 对象处拆分 jq 输出

c - 使用 nohup 或 setsid 逃避 alarm() 进程超时?

linux - 匹配时如何退出 Sed

linux - Azure Add-AzureProvisioningConfig ssh key 或 key 对上传

Linux xargs 命令

linux - 在 Ubuntu 服务器上运行 QT-GUI 程序

linux - 在 .*sh 文件中启动一个新的 shell

regex - 用 sed 替换控制字符

ruby - 中间人问我是否要在开始新项目时使用 compass

linux - 逐行读取文件并在每行中打印第一个匹配项,或者在没有匹配项时打印 "no_data"