Subject: Re: bug#38706: error

From: Assaf Gordon <[email-masked]>
Date: Sun, 22 Dec 2019 12:49:48 -0700

tag 38706 moreinfo
stop

Hello,

On 2019-12-22 2:37 a.m., Garn-Bachmann wrote:
>     Inserting characters at the end leads to errors
>     cat ~/te.txt | sed 's|$|h|g'
>     h036
>     h110
>     h110

I suspect this is an issue with end-of-line characters
being "\r\n" (CR LF) in the input file.

The '$' regex matches the end of the line,
which would be AFTER the "\r". The text line becomes "0036\rh\n"
which causes the output you are seeing.

For example:

   $ printf '%s\r\n' aaa bbb ccc | sed 's|$|h|g'
   haa
   hbb
   hcc

---

There are many ways to remove the carriage return (\r) characters.
For example:

Using sed:

   $ printf '%s\r\n' aaa bbb ccc | sed 's|\r|| ; s|$|h|g'
   aaah
   bbbh
   ccch

Using "tr":

   $ printf '%s\r\n' aaa bbb ccc | tr -d '\r' | sed 's|$|h|g'
   aaah
   bbbh
   ccch

Or using the "dos2unix" programs.

---

If this solves the issue - great.
If not, please share the input file (te.txt) to help us
diagnose the issue better.
You can send it to me privately off-list if you prefer.

regards,
  - assaf