sed alters windows line endings unintentionally. How can I avoid that?

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to unix.
The code -using 'sed'- was simple enough to find online:
sed -i.bak -E 's/[[:space:]]+$//' myfile
the problem is that after the operation, diff states that ALL lines in the file (and the .bak that was generated) differ. This cannot be true of course. The specific file had only 1 line with a trailing space.
Checking with a hexdump (I used od -x myfile) utility it is apparent that the 1st line of the original file ends in "0d0a" , whereas in the sed-edited file it ends in "0a".
I have not been able to find any information about how to perform the trailing spaces removal without affecting the line endings. Is there a way ?
if the "Carriage return" character is part of the "[[:space:]]" regex group, then perhaps this
sed -i.bak -E 's/[ t]+$//' myfile
should work. But it does not - it creates an identical file.
I have also tried the "-e" flag and even no flag at all. Still the generated file is identical to the original and no trailing space is removed.
sed newlines whitespace
add a comment |Â
up vote
0
down vote
favorite
I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to unix.
The code -using 'sed'- was simple enough to find online:
sed -i.bak -E 's/[[:space:]]+$//' myfile
the problem is that after the operation, diff states that ALL lines in the file (and the .bak that was generated) differ. This cannot be true of course. The specific file had only 1 line with a trailing space.
Checking with a hexdump (I used od -x myfile) utility it is apparent that the 1st line of the original file ends in "0d0a" , whereas in the sed-edited file it ends in "0a".
I have not been able to find any information about how to perform the trailing spaces removal without affecting the line endings. Is there a way ?
if the "Carriage return" character is part of the "[[:space:]]" regex group, then perhaps this
sed -i.bak -E 's/[ t]+$//' myfile
should work. But it does not - it creates an identical file.
I have also tried the "-e" flag and even no flag at all. Still the generated file is identical to the original and no trailing space is removed.
sed newlines whitespace
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to unix.
The code -using 'sed'- was simple enough to find online:
sed -i.bak -E 's/[[:space:]]+$//' myfile
the problem is that after the operation, diff states that ALL lines in the file (and the .bak that was generated) differ. This cannot be true of course. The specific file had only 1 line with a trailing space.
Checking with a hexdump (I used od -x myfile) utility it is apparent that the 1st line of the original file ends in "0d0a" , whereas in the sed-edited file it ends in "0a".
I have not been able to find any information about how to perform the trailing spaces removal without affecting the line endings. Is there a way ?
if the "Carriage return" character is part of the "[[:space:]]" regex group, then perhaps this
sed -i.bak -E 's/[ t]+$//' myfile
should work. But it does not - it creates an identical file.
I have also tried the "-e" flag and even no flag at all. Still the generated file is identical to the original and no trailing space is removed.
sed newlines whitespace
I am developing in linux a portable application, in which I wanted to remove trailing spaces from some source files, which have windows style line endings. The line endings should not be changed to unix.
The code -using 'sed'- was simple enough to find online:
sed -i.bak -E 's/[[:space:]]+$//' myfile
the problem is that after the operation, diff states that ALL lines in the file (and the .bak that was generated) differ. This cannot be true of course. The specific file had only 1 line with a trailing space.
Checking with a hexdump (I used od -x myfile) utility it is apparent that the 1st line of the original file ends in "0d0a" , whereas in the sed-edited file it ends in "0a".
I have not been able to find any information about how to perform the trailing spaces removal without affecting the line endings. Is there a way ?
if the "Carriage return" character is part of the "[[:space:]]" regex group, then perhaps this
sed -i.bak -E 's/[ t]+$//' myfile
should work. But it does not - it creates an identical file.
I have also tried the "-e" flag and even no flag at all. Still the generated file is identical to the original and no trailing space is removed.
sed newlines whitespace
sed newlines whitespace
asked 1 min ago
nass
64621431
64621431
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476582%2fsed-alters-windows-line-endings-unintentionally-how-can-i-avoid-that%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password