linux - 在不同的列中写入变量?

标签 linux bash shell

我想将只有一列的文件转换为具有不同列的文件。 在这个初始文件中,我有 4 个变量。每个变量写 10 行,我想要 4 列,每列 10 行。

图形化:

我有:

1
1
2
2
3
3
4
4

我想要什么:

1 2 3 4
1 2 3 4

最佳答案

如果将变量的行保存到各自的文件中,则可以使用 paste 来实现此目的。

$ # generating example files:
$ seq 1 10 > file1
$ seq 11 20 > file2
$ seq 21 30 > file3
$ seq 31 40 > file4
$ # showing contents of the files:
$ cat file{1..4}
1 # first file
2
3
4
5
6
7
8
9
10
11 # second file
12
13
14
15
16
17
18
19
20
21 # third file
22
23
24
25
26
27
28
29
30
31 # fourth file
32
33
34
35
36
37
38
39
40
$ paste file{1..4}
1   11  21  31
2   12  22  32
3   13  23  33
4   14  24  34
5   15  25  35
6   16  26  36
7   17  27  37
8   18  28  38
9   19  29  39
10  20  30  40

关于linux - 在不同的列中写入变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16562931/

相关文章:

linux - 在 Fortran 代码中执行 execute_command_line() 时出错

linux - Linux 代码块中的复制/粘贴功能

linux - 查找连接到 Linux 机器的所有存储设备

linux - bash 脚本,第 30 行 : syntax error: unexpected end of file

json - 使用 JQ Issue 解析复杂的 JSON 文件

bash - 带换行符的管道字符串到 bash 中的命令?

linux - Groovy 中 JAVA_HOME 未正确定义

linux - nroff/groff 不能正确转换 utf-8 编码的文件

linux - 如何在 Linux shell 中执行 'where' 子句?

c - 使用流在 *nix 进程之间传输输入/输出