Remove “n” string from end of certain lines

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











up vote
2
down vote

favorite
1












How do I remove the string "n" (not the newline character) from the end of only lines that begin with the string "///"? Thanks.



Example Input:



Some textn

/// Some commentn


Desired Output:



Some textn

/// Some comment


I've tried to use



sed -i 's/\n*$//' $1


But, it removes all of the trailing "n" strings.







share|improve this question























    up vote
    2
    down vote

    favorite
    1












    How do I remove the string "n" (not the newline character) from the end of only lines that begin with the string "///"? Thanks.



    Example Input:



    Some textn

    /// Some commentn


    Desired Output:



    Some textn

    /// Some comment


    I've tried to use



    sed -i 's/\n*$//' $1


    But, it removes all of the trailing "n" strings.







    share|improve this question





















      up vote
      2
      down vote

      favorite
      1









      up vote
      2
      down vote

      favorite
      1






      1





      How do I remove the string "n" (not the newline character) from the end of only lines that begin with the string "///"? Thanks.



      Example Input:



      Some textn

      /// Some commentn


      Desired Output:



      Some textn

      /// Some comment


      I've tried to use



      sed -i 's/\n*$//' $1


      But, it removes all of the trailing "n" strings.







      share|improve this question











      How do I remove the string "n" (not the newline character) from the end of only lines that begin with the string "///"? Thanks.



      Example Input:



      Some textn

      /// Some commentn


      Desired Output:



      Some textn

      /// Some comment


      I've tried to use



      sed -i 's/\n*$//' $1


      But, it removes all of the trailing "n" strings.









      share|improve this question










      share|improve this question




      share|improve this question









      asked Jul 11 at 23:30









      caleb_hendrix

      133




      133




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Add a regex address specifier at the front - since your pattern has forward slashes, it's clearer if you use a different expression separator:



          sed -i '%^///% s/\n$//' Input


          Testing:



          $ sed '%^///% s/\n$//' Input 
          Some textn

          /// Some comment


          If you prefer "leaning toothpicks"



          sed -i '/^//// s/\n$//' Input





          share|improve this answer





















            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%2f454796%2fremove-n-string-from-end-of-certain-lines%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            Add a regex address specifier at the front - since your pattern has forward slashes, it's clearer if you use a different expression separator:



            sed -i '%^///% s/\n$//' Input


            Testing:



            $ sed '%^///% s/\n$//' Input 
            Some textn

            /// Some comment


            If you prefer "leaning toothpicks"



            sed -i '/^//// s/\n$//' Input





            share|improve this answer

























              up vote
              2
              down vote



              accepted










              Add a regex address specifier at the front - since your pattern has forward slashes, it's clearer if you use a different expression separator:



              sed -i '%^///% s/\n$//' Input


              Testing:



              $ sed '%^///% s/\n$//' Input 
              Some textn

              /// Some comment


              If you prefer "leaning toothpicks"



              sed -i '/^//// s/\n$//' Input





              share|improve this answer























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                Add a regex address specifier at the front - since your pattern has forward slashes, it's clearer if you use a different expression separator:



                sed -i '%^///% s/\n$//' Input


                Testing:



                $ sed '%^///% s/\n$//' Input 
                Some textn

                /// Some comment


                If you prefer "leaning toothpicks"



                sed -i '/^//// s/\n$//' Input





                share|improve this answer













                Add a regex address specifier at the front - since your pattern has forward slashes, it's clearer if you use a different expression separator:



                sed -i '%^///% s/\n$//' Input


                Testing:



                $ sed '%^///% s/\n$//' Input 
                Some textn

                /// Some comment


                If you prefer "leaning toothpicks"



                sed -i '/^//// s/\n$//' Input






                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jul 11 at 23:35









                steeldriver

                30.9k34877




                30.9k34877






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f454796%2fremove-n-string-from-end-of-certain-lines%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