从cut命令强制输出字段的顺序 [英] Forcing the order of output fields from cut command

查看:640
本文介绍了从cut命令强制输出字段的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做这样的事情:

cat abcd.txt | cut -f 2,1

和我想要的顺序为2,然后在输出1。在机器我测试(FreeBSD的6),这是不会发生(它在1,2顺序打印)。你能告诉我如何做到这一点?

and I want the order to be 2 and then 1 in the output. On the machine I am testing (FreeBSD 6), this is not happening (its printing in 1,2 order). Can you tell me how to do this?

我知道我可以写一个shell脚本来完成这个逆转,但我现在用的是剪切命令选项寻找的东西。

I know I can always write a shell script to do this reversing, but I am looking for something using the 'cut' command options.

我想我使用含切的coreutils的5.2.1版本。

I think I am using version 5.2.1 of coreutils containing cut.

推荐答案

这不能使用的剪切的完成。根据该手册页:

This can't be done using cut. According to the man page:

选择输入被写在相同的顺序,它被读取,并且被写入一次。

相反,你可以用它做的 AWK 的,是这样的:

Instead, you can do it using awk, like this:

awk '{print($2,"\t",$1)}' abcd.txt

与您正在使用的字段分隔任何替换\\吨。

Replace the \t with whatever you're using as field separator.

这篇关于从cut命令强制输出字段的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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