Unix 粘贴的行重叠不正确

Unix 粘贴的行重叠不正确

我有一个名为 的文件file1,其中包含以下几行

you are searching for a four .
you are searching for a six .
you are searching for a three .
you are searching for an ace .
you are searching for an eight .
you can use empty spaces in the Tab@@ le@@ au to move multiple cards . be careful with K@@ ings in the Reserve : the only way to remove them is by playing them to a Foundation on top of a Queen .
you can use empty spaces in the Tab@@ le@@ au to move multiple cards . be careful with K@@ ings in the Reserve : the only way to remove them is by playing them to a Foundation on top of a Queen .

我有第二个文件,file2用这些行调用

four|||Vier
six|||Se@@ chs
for|||nach
searching|||suchen
eight|||Acht
spaces|||Plätze
spaces|||Plätze spaces|||Plätze

但是,在我通过 Unix 粘贴执行合并这些行的命令之后

paste file1 file2 > result

我得到的结果是这样的:

you are four|||Vieror a four .
you are six|||Se@@ chsa six .
you are for|||nachfor a three .
you are searching|||suchence .
you are eight|||Achtr an eight .
you can use empty spaces in the Tab@@ le@@ au to move multiple cards . be careful with K@@ ings in the Reserve : the only way to remove them is by playing them to a Fouspaces|||Plätzeof a Queen .
you can use empty spaces in the Tab@@ le@@ au to move multiple cards . be careful with K@@ ings in the Reserve : the only way to remove them is by playing them to a Foundation on top of a Queen .     spaces|||Plätze spaces|||Plätze

我不明白发生了什么事。为什么每个文件中的合并行重叠?

答案1

我猜至少file1是一个 DOS 文本文件。在 Unix 系统上使用时,此类文件中的每一行末尾都会有一个额外的回车符。当将其打印到终端时,此回车符将光标带回到行的开头。在两个文件的数据之间插入的制表符paste将光标向右移动八个字符。然后,第二个文件中的文本会覆盖该行的内容,从而导致您看到的乱码输出。

您可能需要使用以下工具转换文本文件dos2unix(这也可以正确地将文件从常见的 Windows 文本编码转换为 Unix 等上更常用的编码)

相关内容