问题描述
类似
Append one column from fileB onto end of FileA 和 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
所需的输出 // 我想将 file2.txt 的第二列合并/附加到 file1.txt(最终文件有 4 列):
>file1.txt
4481679 4481722 . -
4481791 4481820 . +
4481947 4482268 . -
错误 // 到目前为止,我已经尝试了以下(看起来都正确 - 就像上面一样),但每个都只是简单地打印到标准输出:
Attempt1:
$ paste file1.txt <(cut -f2 file2.txt)
Attempt2:
$ cut -f2 file2.txt | paste file1.txt -
Attempt3:
$ paste file1.txt <(awk '{print $2}' 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 之类的东西)吗?
解决方法
像这样使用 cut
和 paste
:
paste file1.txt <(cut -f2 file2.txt) > out_file.txt
您的错误与您的磁盘已满有关。删除多余的文件以释放一些空间。