producing extra rows when pasting two files

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

producing extra rows when pasting two files

Lichi
I have two files.

file1.txt
a b c d
e r t y
v b n m

file2.txt
1
2
3

I used command paste as: paste file2.txt file1.txt
The result is:
1
 a b c d
2
 e r t y
3
 v b n m

The desired result should be:
1 a b c d
2 e r t y
3 v b n m

Does anyone know how to fix it? Many thanks.
Reply | Threaded
Open this post in threaded view
|

Re: producing extra rows when pasting two files

Guru
Administrator
It looks like file2.txt has ^M characters, and hence the issue. Run the dos2unix command on the file2.txt and then try the paste command.
Dee
Reply | Threaded
Open this post in threaded view
|

Re: producing extra rows when pasting two files

Dee
In reply to this post by Lichi
You can try like this:

paste file1.txt file2.txt>file3.txt |awk '{print $1,$2,$3,$4,$5}' file3.txt
Dee
Reply | Threaded
Open this post in threaded view
|

Re: producing extra rows when pasting two files

Dee
In reply to this post by Lichi
paste file2.txt file1.txt>file3.txt |awk '{print $1,$2,$3,$4,$5}' file3.txt