Files

Unix 粘貼的線重疊不正確

  • January 29, 2022

我有一個名為 的文件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 合併這些行的命令之後

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

我不明白髮生了什麼。為什麼每個文件的合併行重疊?

我猜至少file1是一個DOS文本文件。在 Unix 系統上使用時,此類文件中的每一行末尾都會有一個額外的輸入符。當它被列印到終端時,這個輸入字元將游標帶回到行首。在兩個文件的數據之間插入的製表符paste將游標向右移動八個字元。然後,第二個文件中的文本會覆蓋該行的內容,從而產生您看到的亂碼輸出。

您可能希望使用以下工具轉換文本文件dos2unix(這也可以正確地將文件從常見的 Windows 文本編碼轉換為 Unix 上更常用的編碼等)

引用自:https://unix.stackexchange.com/questions/688461