Pregunta

I tried to concatenate a column to a text file. The column looks like this:

14_00

132_1



343_12

23


2
2_1

It is made of numbers and spaces (when no number is specified)

The other file I want to add this column to (at the beginning of the file) is made of numbers separated by tabs ans has the same number of rows as the first file.

I tried the following command:

paste -d "\t" file1.txt file2.txt > merged.txt

It works fine except that, for some reason, I have a "^M" at the end of the first column.

Where does this ^M come from and how can I get rid of it? I tried changing the delimiters in the paste options, but the problem remains.

¿Fue útil?

Solución

I have a "^M" at the end of the first

That means you have \r in the files itself.

To get rid of them you can use this sed:

sed -i.bak $'s/\r$//' file

OR use: dos2unix utility.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top