Why does Copy&Paste remove Carriage Return?

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read how to get help
Post Reply
alex2356
Level 1
Level 1
Posts: 3
Joined: Thu Feb 15, 2018 8:12 am

Why does Copy&Paste remove Carriage Return?

Post by alex2356 » Thu Feb 15, 2018 8:46 am

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

User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1438
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: Why does Copy&Paste remove Carriage Return?

Post by Pilosopong Tasyo » Thu Feb 15, 2018 9:43 am

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.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].

User avatar
xenopeek
Level 24
Level 24
Posts: 22763
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Why does Copy&Paste remove Carriage Return?

Post by xenopeek » Thu Feb 15, 2018 9:53 am

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:
Image

alex2356
Level 1
Level 1
Posts: 3
Joined: Thu Feb 15, 2018 8:12 am

Re: Why does Copy&Paste remove Carriage Return?

Post by alex2356 » Thu Feb 15, 2018 10:50 am

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 ... :)

Post Reply

Return to “Newbie Questions”