Remove special characters at end of row in unix file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I have a csv file which has a delimiter ~@~~@~ and sometimes ~@~. Same set of special characters ~@~~@~(I dont know how many but ~@~~@~*) appear at end of row which is a date field. So data in file is like



ABC~@~~@~TUV~@~~@~XYZ~@~PQR~@~13470~@~Management~@~Non-Employee IJK~@~T~@~12345~@~12345~@~abc@gmail.com~@~B~@~~@~~@~~@~6789~@~09/25/2017 11:31:22.000000~@~09/25/2017 3:22:03.000000~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~n


I need to remove the characters from Last Date field to End of line.
I have tried sed 's/~@~~@~~@~n*//g' File name>Replacedfilename.txt, but it retains one set of special characters at the end. Kindly provide your inputs







share|improve this question






















  • post the expected result
    – RomanPerekhrest
    Dec 14 '17 at 19:46






  • 2




    If it is a CSV file with a special delimiter, then it seems more plausible that ~@~~@~ is an empty column (similar to ,, in a CSV file with comma delimiters). If there are programs reading this file and you get rid of empty columns, are you sure that they are still going to work?
    – NickD
    Dec 14 '17 at 20:24














up vote
0
down vote

favorite












I have a csv file which has a delimiter ~@~~@~ and sometimes ~@~. Same set of special characters ~@~~@~(I dont know how many but ~@~~@~*) appear at end of row which is a date field. So data in file is like



ABC~@~~@~TUV~@~~@~XYZ~@~PQR~@~13470~@~Management~@~Non-Employee IJK~@~T~@~12345~@~12345~@~abc@gmail.com~@~B~@~~@~~@~~@~6789~@~09/25/2017 11:31:22.000000~@~09/25/2017 3:22:03.000000~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~n


I need to remove the characters from Last Date field to End of line.
I have tried sed 's/~@~~@~~@~n*//g' File name>Replacedfilename.txt, but it retains one set of special characters at the end. Kindly provide your inputs







share|improve this question






















  • post the expected result
    – RomanPerekhrest
    Dec 14 '17 at 19:46






  • 2




    If it is a CSV file with a special delimiter, then it seems more plausible that ~@~~@~ is an empty column (similar to ,, in a CSV file with comma delimiters). If there are programs reading this file and you get rid of empty columns, are you sure that they are still going to work?
    – NickD
    Dec 14 '17 at 20:24












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a csv file which has a delimiter ~@~~@~ and sometimes ~@~. Same set of special characters ~@~~@~(I dont know how many but ~@~~@~*) appear at end of row which is a date field. So data in file is like



ABC~@~~@~TUV~@~~@~XYZ~@~PQR~@~13470~@~Management~@~Non-Employee IJK~@~T~@~12345~@~12345~@~abc@gmail.com~@~B~@~~@~~@~~@~6789~@~09/25/2017 11:31:22.000000~@~09/25/2017 3:22:03.000000~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~n


I need to remove the characters from Last Date field to End of line.
I have tried sed 's/~@~~@~~@~n*//g' File name>Replacedfilename.txt, but it retains one set of special characters at the end. Kindly provide your inputs







share|improve this question














I have a csv file which has a delimiter ~@~~@~ and sometimes ~@~. Same set of special characters ~@~~@~(I dont know how many but ~@~~@~*) appear at end of row which is a date field. So data in file is like



ABC~@~~@~TUV~@~~@~XYZ~@~PQR~@~13470~@~Management~@~Non-Employee IJK~@~T~@~12345~@~12345~@~abc@gmail.com~@~B~@~~@~~@~~@~6789~@~09/25/2017 11:31:22.000000~@~09/25/2017 3:22:03.000000~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~~@~n


I need to remove the characters from Last Date field to End of line.
I have tried sed 's/~@~~@~~@~n*//g' File name>Replacedfilename.txt, but it retains one set of special characters at the end. Kindly provide your inputs









share|improve this question













share|improve this question




share|improve this question








edited Dec 14 '17 at 19:37









nwildner

13.2k14071




13.2k14071










asked Dec 14 '17 at 19:32









Manju

1




1











  • post the expected result
    – RomanPerekhrest
    Dec 14 '17 at 19:46






  • 2




    If it is a CSV file with a special delimiter, then it seems more plausible that ~@~~@~ is an empty column (similar to ,, in a CSV file with comma delimiters). If there are programs reading this file and you get rid of empty columns, are you sure that they are still going to work?
    – NickD
    Dec 14 '17 at 20:24
















  • post the expected result
    – RomanPerekhrest
    Dec 14 '17 at 19:46






  • 2




    If it is a CSV file with a special delimiter, then it seems more plausible that ~@~~@~ is an empty column (similar to ,, in a CSV file with comma delimiters). If there are programs reading this file and you get rid of empty columns, are you sure that they are still going to work?
    – NickD
    Dec 14 '17 at 20:24















post the expected result
– RomanPerekhrest
Dec 14 '17 at 19:46




post the expected result
– RomanPerekhrest
Dec 14 '17 at 19:46




2




2




If it is a CSV file with a special delimiter, then it seems more plausible that ~@~~@~ is an empty column (similar to ,, in a CSV file with comma delimiters). If there are programs reading this file and you get rid of empty columns, are you sure that they are still going to work?
– NickD
Dec 14 '17 at 20:24




If it is a CSV file with a special delimiter, then it seems more plausible that ~@~~@~ is an empty column (similar to ,, in a CSV file with comma delimiters). If there are programs reading this file and you get rid of empty columns, are you sure that they are still going to work?
– NickD
Dec 14 '17 at 20:24










3 Answers
3






active

oldest

votes

















up vote
3
down vote













... | sed 's/(~@~)*$//'


to remove any number of ~@~ at end of line (assuming of course that the n in your sample represents the line-ending newline, and not a literal backslash and lowercase N.)



or in seds that support -E for extended regular expressions:



... | sed -E 's/(~@~)+$//' 


or you could use awk -F'~@~' and handle the fields you need to at the same time.






share|improve this answer





























    up vote
    0
    down vote













    Assuming the above data is in file f1.txt.
    We can use the sed command and remove every occurrence of ~@~~@~ and ~@~.
    I've replaced it with a blank space.



    sed -e 's/~@~~@~/#/g;s/~@~/#/g;s/# */ /g' f1.txt > output.txt


    Result



    ABC TUV XYZ PQR 13470 Management Non-Employee IJK T 12345 12345 abc@gmail.com B 6789 09/25/2017 11:31:22.000000 09/25/2017 3:22:03.000000





    share|improve this answer



























      up vote
      -1
      down vote













      cat file |sed 's/~@~~@~~@~//g' |sed 's/~@~$//'


      the first sed remove the string ~@~~@~ and the second sed remove the last ~@~






      share|improve this answer






















      • it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
        – Emilio Galarraga
        Dec 14 '17 at 20:15










      • There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
        – NickD
        Dec 14 '17 at 20:20










      • Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
        – ilkkachu
        Dec 14 '17 at 20:27











      • @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
        – ilkkachu
        Dec 14 '17 at 20:27






      • 1




        @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
        – ilkkachu
        Dec 15 '17 at 11:39










      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%2f410934%2fremove-special-characters-at-end-of-row-in-unix-file%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote













      ... | sed 's/(~@~)*$//'


      to remove any number of ~@~ at end of line (assuming of course that the n in your sample represents the line-ending newline, and not a literal backslash and lowercase N.)



      or in seds that support -E for extended regular expressions:



      ... | sed -E 's/(~@~)+$//' 


      or you could use awk -F'~@~' and handle the fields you need to at the same time.






      share|improve this answer


























        up vote
        3
        down vote













        ... | sed 's/(~@~)*$//'


        to remove any number of ~@~ at end of line (assuming of course that the n in your sample represents the line-ending newline, and not a literal backslash and lowercase N.)



        or in seds that support -E for extended regular expressions:



        ... | sed -E 's/(~@~)+$//' 


        or you could use awk -F'~@~' and handle the fields you need to at the same time.






        share|improve this answer
























          up vote
          3
          down vote










          up vote
          3
          down vote









          ... | sed 's/(~@~)*$//'


          to remove any number of ~@~ at end of line (assuming of course that the n in your sample represents the line-ending newline, and not a literal backslash and lowercase N.)



          or in seds that support -E for extended regular expressions:



          ... | sed -E 's/(~@~)+$//' 


          or you could use awk -F'~@~' and handle the fields you need to at the same time.






          share|improve this answer














          ... | sed 's/(~@~)*$//'


          to remove any number of ~@~ at end of line (assuming of course that the n in your sample represents the line-ending newline, and not a literal backslash and lowercase N.)



          or in seds that support -E for extended regular expressions:



          ... | sed -E 's/(~@~)+$//' 


          or you could use awk -F'~@~' and handle the fields you need to at the same time.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 15 '17 at 11:33

























          answered Dec 14 '17 at 20:10









          ilkkachu

          49.9k674137




          49.9k674137






















              up vote
              0
              down vote













              Assuming the above data is in file f1.txt.
              We can use the sed command and remove every occurrence of ~@~~@~ and ~@~.
              I've replaced it with a blank space.



              sed -e 's/~@~~@~/#/g;s/~@~/#/g;s/# */ /g' f1.txt > output.txt


              Result



              ABC TUV XYZ PQR 13470 Management Non-Employee IJK T 12345 12345 abc@gmail.com B 6789 09/25/2017 11:31:22.000000 09/25/2017 3:22:03.000000





              share|improve this answer
























                up vote
                0
                down vote













                Assuming the above data is in file f1.txt.
                We can use the sed command and remove every occurrence of ~@~~@~ and ~@~.
                I've replaced it with a blank space.



                sed -e 's/~@~~@~/#/g;s/~@~/#/g;s/# */ /g' f1.txt > output.txt


                Result



                ABC TUV XYZ PQR 13470 Management Non-Employee IJK T 12345 12345 abc@gmail.com B 6789 09/25/2017 11:31:22.000000 09/25/2017 3:22:03.000000





                share|improve this answer






















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Assuming the above data is in file f1.txt.
                  We can use the sed command and remove every occurrence of ~@~~@~ and ~@~.
                  I've replaced it with a blank space.



                  sed -e 's/~@~~@~/#/g;s/~@~/#/g;s/# */ /g' f1.txt > output.txt


                  Result



                  ABC TUV XYZ PQR 13470 Management Non-Employee IJK T 12345 12345 abc@gmail.com B 6789 09/25/2017 11:31:22.000000 09/25/2017 3:22:03.000000





                  share|improve this answer












                  Assuming the above data is in file f1.txt.
                  We can use the sed command and remove every occurrence of ~@~~@~ and ~@~.
                  I've replaced it with a blank space.



                  sed -e 's/~@~~@~/#/g;s/~@~/#/g;s/# */ /g' f1.txt > output.txt


                  Result



                  ABC TUV XYZ PQR 13470 Management Non-Employee IJK T 12345 12345 abc@gmail.com B 6789 09/25/2017 11:31:22.000000 09/25/2017 3:22:03.000000






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 14 '17 at 20:57









                  Prashant Luhar

                  336




                  336




















                      up vote
                      -1
                      down vote













                      cat file |sed 's/~@~~@~~@~//g' |sed 's/~@~$//'


                      the first sed remove the string ~@~~@~ and the second sed remove the last ~@~






                      share|improve this answer






















                      • it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
                        – Emilio Galarraga
                        Dec 14 '17 at 20:15










                      • There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
                        – NickD
                        Dec 14 '17 at 20:20










                      • Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
                        – ilkkachu
                        Dec 14 '17 at 20:27











                      • @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
                        – ilkkachu
                        Dec 14 '17 at 20:27






                      • 1




                        @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
                        – ilkkachu
                        Dec 15 '17 at 11:39














                      up vote
                      -1
                      down vote













                      cat file |sed 's/~@~~@~~@~//g' |sed 's/~@~$//'


                      the first sed remove the string ~@~~@~ and the second sed remove the last ~@~






                      share|improve this answer






















                      • it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
                        – Emilio Galarraga
                        Dec 14 '17 at 20:15










                      • There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
                        – NickD
                        Dec 14 '17 at 20:20










                      • Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
                        – ilkkachu
                        Dec 14 '17 at 20:27











                      • @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
                        – ilkkachu
                        Dec 14 '17 at 20:27






                      • 1




                        @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
                        – ilkkachu
                        Dec 15 '17 at 11:39












                      up vote
                      -1
                      down vote










                      up vote
                      -1
                      down vote









                      cat file |sed 's/~@~~@~~@~//g' |sed 's/~@~$//'


                      the first sed remove the string ~@~~@~ and the second sed remove the last ~@~






                      share|improve this answer














                      cat file |sed 's/~@~~@~~@~//g' |sed 's/~@~$//'


                      the first sed remove the string ~@~~@~ and the second sed remove the last ~@~







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Dec 15 '17 at 10:52

























                      answered Dec 14 '17 at 19:45









                      Emilio Galarraga

                      32628




                      32628











                      • it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
                        – Emilio Galarraga
                        Dec 14 '17 at 20:15










                      • There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
                        – NickD
                        Dec 14 '17 at 20:20










                      • Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
                        – ilkkachu
                        Dec 14 '17 at 20:27











                      • @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
                        – ilkkachu
                        Dec 14 '17 at 20:27






                      • 1




                        @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
                        – ilkkachu
                        Dec 15 '17 at 11:39
















                      • it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
                        – Emilio Galarraga
                        Dec 14 '17 at 20:15










                      • There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
                        – NickD
                        Dec 14 '17 at 20:20










                      • Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
                        – ilkkachu
                        Dec 14 '17 at 20:27











                      • @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
                        – ilkkachu
                        Dec 14 '17 at 20:27






                      • 1




                        @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
                        – ilkkachu
                        Dec 15 '17 at 11:39















                      it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
                      – Emilio Galarraga
                      Dec 14 '17 at 20:15




                      it doesn't remove the ~@~ delimiters, the first sed removes the string ~@~~@~ and the second removes the ~@~ that remains at the end of the line
                      – Emilio Galarraga
                      Dec 14 '17 at 20:15












                      There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
                      – NickD
                      Dec 14 '17 at 20:20




                      There's a pipe missing (although it would be better to get rid of the cat altogether). Also as @ilkkachu points out, you are getting rid of things in the middle of the line and you are only getting rid of a single delimiter at the end of the line.
                      – NickD
                      Dec 14 '17 at 20:20












                      Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
                      – ilkkachu
                      Dec 14 '17 at 20:27





                      Sorry, I mean it removes the ~@~~@~'s from the middle of the line, as in the beginning of the sample, here: ABC~@~~@~TUV. Not the single ~@~'s, of course.
                      – ilkkachu
                      Dec 14 '17 at 20:27













                      @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
                      – ilkkachu
                      Dec 14 '17 at 20:27




                      @Nick, at EOL, it works, since the first one removes all doubled ~@~'s, and the second removes the single one potentially left over at the end.
                      – ilkkachu
                      Dec 14 '17 at 20:27




                      1




                      1




                      @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
                      – ilkkachu
                      Dec 15 '17 at 11:39




                      @user3333911, well, that will still remove the ~@~'s in the middle, if some input happens to have two adjacent empty columns. That's not really a robust feature if the aim is to only remove the ones at the end of line. Now it will also leave one ~@~ in the end if their count is one less than a multiple of three (i.e. 3n + 2)
                      – ilkkachu
                      Dec 15 '17 at 11:39












                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f410934%2fremove-special-characters-at-end-of-row-in-unix-file%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay