如何使用 awk/sed 整理无序的列?

如何使用 awk/sed 整理无序的列?

我有两列,包括一些数据,例如:

one      two
one two
one    two

我们如何将其转换为:

one two
one two
one two

答案1

Awk-使用默认(单个空格)输出字段分隔符重写字段:

$ awk '{NF+=0} 1' data
one two
one two
one two

Sed-用单个空格替换多个空格:

$ sed 's/  */ /' data
one two
one two
one two

tr——挤压(-s)空格:

$ tr -s ' ' < data
one two
one two
one two

柱子:

$ column -t < data
one  two
one  two
one  two

rs(重塑)为两列:

$ rs 0 2 < data
one  two
one  two
one  two

相关内容