UNIX遍历.txt文件并将其逐行合并为单个文件

时间:2019-03-19 19:44:49

标签: shell file unix merge iteration

假设我在UNIX shell上有3个不同的.txt文件。我想将不同的文件合并为一个文件。我还需要创建该文件并逐行写入。

采用以下示例:

file1.txt:

-abc

-def

-ghi

file2.txt:

-123

-456

-789

file3.txt:

-***

-^^^

-´´´

我需要将combinedFile写入并以这种格式保存:

combinedFile.txt

abc 123 ***

def 456 ^^^

ghi 789´´

1 个答案:

答案 0 :(得分:1)

剪切,例如:

cut -d- -f2 file1 > file11

粘贴,例如:

paste -d' ' file11 file22 file33