使用cut重新排列列 [英] Rearrange columns using cut

查看:128
本文介绍了使用cut重新排列列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下格式的文件

I am having a file in the following format


Column1    Column2
str1       1
str2       2
str3       3

我希望重新排列列。我在命令下面尝试过

I want the columns to be rearranged. I tried below command


cut -f2,1 file.txt

cut -f2,1 file.txt

该命令不会对列重新排序。知道为什么它不起作用吗?

The command doesn't reorder the columns. Any idea why its not working?

谢谢。

推荐答案

对于 cut(1)手册页:


仅使用一个, -b,-c或-f。每个LIST由
组成一个
范围,或由逗号分隔的许多范围。所选输入将按照与读取相同的顺序写入
,并且只被写入一次。

Use one, and only one of -b, -c or -f. Each LIST is made up of one range, or many ranges separated by commas. Selected input is written in the same order that it is read, and is written exactly once.

到达字段1首先打印出来,然后打印字段2。

It reaches field 1 first, so that is printed, followed by field 2.

使用 awk 代替:

awk '{ print $2 " " $1}' file.txt

这篇关于使用cut重新排列列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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