Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用 UNIX 命令等将文件的第一列附加到另一个文件?
例子:
file1 ----- 10 foo 20x bar 30 baz file2 ----- obama clinton nixon Result: ------- 10 obama 20x clinton 30 nixon
就我而言,file1并且file2保证具有相同的行数。
file1
file2
使用cut和paste:
cut
paste
paste -d ' ' <(cut -d ' ' -f 1 file1) file2
输出:
$ paste -d ' ' <(cut -d ' ' -f 1 file1) file2 10 obama 20x clinton 30 nixon