On 07/02/2021 13:08, KenichiroMATOHARA wrote:
Package: coreutils
Version: 8.32-4+b1
Severity: minor
Dear Maintainer,
When I create a text file with a newline code of "\r\n" and
`cat` with the `-E, --show-ends` option, "$" is displayed at
the beginning of the line.
When `-A, --show-all` is used, it looks normal.
- Create a file for \r\n
$ echo 'foo
$ od -c dos.txt
0000000 f o o \r \n \t b a r \r \n
0000013
bar' | tr '\n' '\r\n' > dos.txt
- `-E, --show-ends` option
$ cat -E dos.txt
$oo
$ bar
$ cat -nE dos.txt
$ 1 foo
$ 2 bar
- `-A, --show-all` option
$ cat -A dos.txt
foo ^M$
^Ibar^M$
$ cat -nA dos.txt
1 foo^M$
2 ^Ibar^M$
I agree the current behavior is less than useful because:
* \r\n is common a line end combination
* catting such a file without options causes it to display normally
* overwriting the first char with $, loses info
I propose to change the upstream coreutils project
as per the attached, to extend the --show-ends option
to show \r as ^M when the following character is \n.
thanks,
Pádraig
diff --git a/src/cat.c b/src/cat.c
index 68f3c9ac5..c9838cfc5 100644
--- a/src/cat.c
+++ b/src/cat.c
@@ -486,7 +486,15 @@ cat (
*bpout++ = ch + 64;
}
else if (ch != '\n')
- *bpout++ = ch;
+ {
+ if (ch == '\r' && (*bpin == '\n') && show_ends)
+ {
+ *bpout++ = '^';
+ *bpout++ = ch + 64;
+ }
+ else
+ *bpout++ = ch;
+ }
else
{
newlines = -1;