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

The name of the pictureThe name of the pictureThe name of the pictureClash 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.









share

























    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.









    share























      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.









      share













      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





      share












      share










      share



      share










      asked 1 min ago









      nass

      64621431




      64621431

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)