如何使用粘贴将一列从 file2 附加到 file1

How to use paste to append one column from file2 to file1

类似于

and bash cut columns to one file and save onto the end of another file

但是,在这种情况下,我希望将结果打印到文件 (file1.txt),而不是标准输出 (stdout)。

背景 // 我有两个制表符分隔的文件(都有 3 列):

>file1.txt
4481679 4481722 .
4481791 4481820 .
4481947 4482268 .

>file2.txt
13368   -       366
13668   +       940
14016   -       270

想要的输出//我想merge/append第二列file2.txt到file1.txt(最终文件有 4 列):

>file1.txt
4481679 4481722 .       -
4481791 4481820 .       +
4481947 4482268 .       -

Errors // 到目前为止,我已经尝试了以下方法(看起来都是正确的——就像上面的一样),但每个都只是打印到标准输出:

    Attempt1:
$ paste file1.txt <(cut -f2 file2.txt)
    Attempt2:
$ cut -f2 file2.txt | paste file1.txt -
    Attempt3:
$ paste file1.txt <(awk '{print }' file2.txt)

此外,以下打印“paste: write error: No space left on device paste: write error”:

    Attempt4:
$ paste file1.txt <(cut -f2 file2.txt) >> file1.txt
    Attempt5:
$ cut -f2 file2.txt | paste file1.txt - > file3.txt

关于如何在不使用 moreutils 中的 sponge 的情况下实现此功能的任何想法(即仅使用粘贴、剪切、awk、sed 之类的东西)?

像这样使用 cutpaste

paste file1.txt <(cut -f2 file2.txt) > out_file.txt

您的错误与您的磁盘已满有关。删除额外的文件以释放一些 space.