Page 1 of 1

Why does Copy&Paste remove Carriage Return?

Posted: Thu Feb 15, 2018 8:46 am
by alex2356
Hello everybody,

I have found the following behavior:

I have a text file unix.txt with the following content:

Code: Select all

A
B
To make it better readable for Windows users I replace the LF with CR LF using unix2dos.
unix2dos -n unix.txt dos.txt

If I now open dos.txt in pluma and copy paste (ctrl+c and ctrl+v) the content into a newly created file copied.txt the Carriage Returns are gone.

My Hex Editor shows me this:

Code: Select all

unix.txt:   41 0A 42 0A
dos.txt:    41 0D 0A 42 0D 0A
copied.txt: 41 0A 42 0A
Question 1: Why does Copy&Paste remove the Carriage Returns?
I would find it better, if Copy&Paste would just copy the data as it is and not change anything.

Question 2: As many companies have contact forms (or even job application forms) on their websites, I often write my message in pluma and then Copy&Paste it to their contact form.
Is it likely that the formatting of my text will be ruined because of missing CR, if the recipient uses Windows?

Thank you in advance

Re: Why does Copy&Paste remove Carriage Return?

Posted: Thu Feb 15, 2018 9:43 am
by Pilosopong Tasyo
1. I don't think copy-paste is the culprit here. Most likely when you saved the copied.txt file, you didn't notice the option to change the line ending from Unix/Linux to Windows. The default option is Unix/Linux.

2.It shouldn't be an issue. You copy-paste the text from Pluma to the website form, and it shows up the way you expect it to show as if you typed it directly.

Re: Why does Copy&Paste remove Carriage Return?

Posted: Thu Feb 15, 2018 9:53 am
by xenopeek
Question 1: you're doing that yourself by NOT specifying the line ending format you want to use for your copied.txt file. When saving a new file, or using the Save As dialog for an existing file, you can set the line endings you want to use for that file. You can set it to Windows there. If you edit the file later and save it again (no need to use Save As or specify the line ending format anew), it will use the line ending format you have earlier saved it with.

Copying and pasting in edit windows on Linux uses Linux line endings. How it is saved to disk is something you specify.

Question 2: similar answer. How they save it to disk on their end and with what line ending format is up to them. In the text edit box on their website you don't need to concern yourself with that. Or have you noticed a lot of ^M codes in text here on the forums from Windows users :wink:

Re: Why does Copy&Paste remove Carriage Return?

Posted: Thu Feb 15, 2018 10:50 am
by alex2356
Thank you very much.

I just tried it out and it really works as you described.

This actually also means, the step with unix2dos was absolutely unnecessary ... :)