Text-Processing

使用帶有串列選項的粘貼的奇怪輸出

  • February 26, 2014

我有一個testA.txt內容如下所示

[jiewmeng@JM textFiles]$ cat testA.txt 
The quick
brown fox
jumped over
the lazy 
dog.

粘貼正常工作

[jiewmeng@JM textFiles]$ paste testA.txt 
The quick
brown fox
jumped over
the lazy 
dog.

但是當我使用串列時發生了什麼?

[jiewmeng@JM textFiles]$ paste -s testA.txt 
The quicdog.lazy er

[jiewmeng@JM textFiles]$ paste -s -d- testA.txt 
-dog.lazy er

我期待輸出類似於

[jiewmeng@JM tmp]$ echo -en "The quick\nbrown fox\njumped over\nthe lazy\ndog" | paste -s -
The quick   brown fox   jumped over the lazy    dog

在測試編輯器中打開文件似乎可以正常工作,就像cat,或者paste

您的文件包含 CR+LF行尾。(你可以這麼說cat -vet inputfile。輸入將顯示^M在輸出中。)

下面展示了行尾對輸出的影響:

$ cat test.txt
The quick
brown fox
jumped over
the lazy
dog.
$ paste -s test.txt
The quick       brown fox       jumped over     the lazy        dog.
$ unix2dos test.txt
$ paste -s test.txt
       dog.lazy er

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