Replace the third comma on each line with newline

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











up vote
7
down vote

favorite












I have these long IDs which consist of four sections:



AKJHGFGUIKL,OIUYT,KJHBTYUI,98765434567
RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL,6789876
ETRYTUUI,YTYUIL,UIOKJHGFGH,34567898766


I want to put the numbers in new line and remove the third comma.



AKJHGFGUIKL,OIUYT,KJHBTYUI
98765434567

RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
6789876

ETRYTUUI,YTYUIL,UIOKJHGFGH
34567898766


How can I do this?










share|improve this question









New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    Hello Simon Q. What have you tried so far?
    – roaima
    17 hours ago






  • 1




    @roaima I tried sed and awk but failed, I spent four hours on this!
    – Simon Q
    13 hours ago










  • @SimonQ, 4 hours, ouch! Anyway, for next time please remember that it helps other learners (among whom are many good people also) to see the failed code. It helps shows them what to avoid.
    – agc
    2 hours ago














up vote
7
down vote

favorite












I have these long IDs which consist of four sections:



AKJHGFGUIKL,OIUYT,KJHBTYUI,98765434567
RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL,6789876
ETRYTUUI,YTYUIL,UIOKJHGFGH,34567898766


I want to put the numbers in new line and remove the third comma.



AKJHGFGUIKL,OIUYT,KJHBTYUI
98765434567

RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
6789876

ETRYTUUI,YTYUIL,UIOKJHGFGH
34567898766


How can I do this?










share|improve this question









New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 3




    Hello Simon Q. What have you tried so far?
    – roaima
    17 hours ago






  • 1




    @roaima I tried sed and awk but failed, I spent four hours on this!
    – Simon Q
    13 hours ago










  • @SimonQ, 4 hours, ouch! Anyway, for next time please remember that it helps other learners (among whom are many good people also) to see the failed code. It helps shows them what to avoid.
    – agc
    2 hours ago












up vote
7
down vote

favorite









up vote
7
down vote

favorite











I have these long IDs which consist of four sections:



AKJHGFGUIKL,OIUYT,KJHBTYUI,98765434567
RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL,6789876
ETRYTUUI,YTYUIL,UIOKJHGFGH,34567898766


I want to put the numbers in new line and remove the third comma.



AKJHGFGUIKL,OIUYT,KJHBTYUI
98765434567

RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
6789876

ETRYTUUI,YTYUIL,UIOKJHGFGH
34567898766


How can I do this?










share|improve this question









New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have these long IDs which consist of four sections:



AKJHGFGUIKL,OIUYT,KJHBTYUI,98765434567
RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL,6789876
ETRYTUUI,YTYUIL,UIOKJHGFGH,34567898766


I want to put the numbers in new line and remove the third comma.



AKJHGFGUIKL,OIUYT,KJHBTYUI
98765434567

RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
6789876

ETRYTUUI,YTYUIL,UIOKJHGFGH
34567898766


How can I do this?







text-processing csv






share|improve this question









New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 12 mins ago









don_crissti

47.7k15126155




47.7k15126155






New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 20 hours ago









Simon Q

503




503




New contributor




Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Simon Q is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 3




    Hello Simon Q. What have you tried so far?
    – roaima
    17 hours ago






  • 1




    @roaima I tried sed and awk but failed, I spent four hours on this!
    – Simon Q
    13 hours ago










  • @SimonQ, 4 hours, ouch! Anyway, for next time please remember that it helps other learners (among whom are many good people also) to see the failed code. It helps shows them what to avoid.
    – agc
    2 hours ago












  • 3




    Hello Simon Q. What have you tried so far?
    – roaima
    17 hours ago






  • 1




    @roaima I tried sed and awk but failed, I spent four hours on this!
    – Simon Q
    13 hours ago










  • @SimonQ, 4 hours, ouch! Anyway, for next time please remember that it helps other learners (among whom are many good people also) to see the failed code. It helps shows them what to avoid.
    – agc
    2 hours ago







3




3




Hello Simon Q. What have you tried so far?
– roaima
17 hours ago




Hello Simon Q. What have you tried so far?
– roaima
17 hours ago




1




1




@roaima I tried sed and awk but failed, I spent four hours on this!
– Simon Q
13 hours ago




@roaima I tried sed and awk but failed, I spent four hours on this!
– Simon Q
13 hours ago












@SimonQ, 4 hours, ouch! Anyway, for next time please remember that it helps other learners (among whom are many good people also) to see the failed code. It helps shows them what to avoid.
– agc
2 hours ago




@SimonQ, 4 hours, ouch! Anyway, for next time please remember that it helps other learners (among whom are many good people also) to see the failed code. It helps shows them what to avoid.
– agc
2 hours ago










5 Answers
5






active

oldest

votes

















up vote
15
down vote



accepted










Using GNU sed:



sed "s/,/n/3; G" file

ETRYTUUI,YTYUIL,UIOKJHGFGH
34567898766


Explanation💡:



sed stands for stream editor..sed has the following syntax:



substitute/match(or pattern)/replacement/position file


In the above command, s substitute the third , by a new line n.



G is to append a new line to the contents of the pattern space and then append the contents of the hold space to the pattern space.






share|improve this answer


















  • 2




    It would be great if you could add a short explanation of how this works for users who don't know sed well.
    – terdon♦
    5 hours ago

















up vote
8
down vote













awk -F, -vOFS=, 'print $1,$2,$3; print $4; print ""' file


will produce your desired output






share|improve this answer



























    up vote
    3
    down vote













    A few Perl approaches:



    $ perl -pe 's/,([^,]+)$/n$1n/' file
    AKJHGFGUIKL,OIUYT,KJHBTYUI
    98765434567

    RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
    6789876

    ETRYTUUI,YTYUIL,UIOKJHGFGH
    34567898766


    The -p means "read the input file line by line and print each line after applying the script given by -e to it". The s/foo/bar/ is the substitution operator which will replace foo with bar. Here, we are matching a comma followed by one or more non-comma characters ([^,]+) until the end of the line ($). The parentheses around the ([^,]+) will "capture" whatever is matched so we can refer to it as $1 on the right hand side of the operator. Therefore, this will replace the text after the last comma with a newline, then the matched text and then another newline.



    If you can't be sure the third comma is the last one, you can do:



    perl -pe 's/([^,]+,)3K(.+)/n$2n/' file


    or



    perl -pe 's/(.+?,.+?,.+?),(.+)/$1n$2n/' file


    And here are some more, just for fun:



    perl -pe 's/([^,]+,)3K(.+)/n$2n/' file
    perl -F, -pe '$k=pop(@F); $_=join(",", @F)."n$kn"' file
    perl -F, -le 'print join ",", @F[0..2],"n@F[3..$#F]n"' file





    share|improve this answer



























      up vote
      2
      down vote













      awk -F, 'print $1, $2, $3,"n"$4'





      share|improve this answer
















      • 2




        You'd need to set OFS=, as well in order to preserve the other delimiters
        – steeldriver
        20 hours ago










      • @steeldriver but it will not remove the third comma as requested?
        – TNT
        20 hours ago











      • ... then change the last part to a simple concatenation $3 "n" $4
        – steeldriver
        20 hours ago











      • This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
        – terdon♦
        5 hours ago

















      up vote
      1
      down vote













      Alternative less succinct sed code:



      sed 's/,([^,]*)/n1n/3' file


      ...which can be used if the hold buffer were needed for some other purpose, (supposing some additional requirement). If you need portable code (the above is gnu sed syntax) use literal newlines in the RHS:



      sed 's/,([^,]*)/
      1
      /3' file





      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
        );



        );






        Simon Q is a new contributor. Be nice, and check out our Code of Conduct.









         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474882%2freplace-the-third-comma-on-each-line-with-newline%23new-answer', 'question_page');

        );

        Post as a guest






























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        15
        down vote



        accepted










        Using GNU sed:



        sed "s/,/n/3; G" file

        ETRYTUUI,YTYUIL,UIOKJHGFGH
        34567898766


        Explanation💡:



        sed stands for stream editor..sed has the following syntax:



        substitute/match(or pattern)/replacement/position file


        In the above command, s substitute the third , by a new line n.



        G is to append a new line to the contents of the pattern space and then append the contents of the hold space to the pattern space.






        share|improve this answer


















        • 2




          It would be great if you could add a short explanation of how this works for users who don't know sed well.
          – terdon♦
          5 hours ago














        up vote
        15
        down vote



        accepted










        Using GNU sed:



        sed "s/,/n/3; G" file

        ETRYTUUI,YTYUIL,UIOKJHGFGH
        34567898766


        Explanation💡:



        sed stands for stream editor..sed has the following syntax:



        substitute/match(or pattern)/replacement/position file


        In the above command, s substitute the third , by a new line n.



        G is to append a new line to the contents of the pattern space and then append the contents of the hold space to the pattern space.






        share|improve this answer


















        • 2




          It would be great if you could add a short explanation of how this works for users who don't know sed well.
          – terdon♦
          5 hours ago












        up vote
        15
        down vote



        accepted







        up vote
        15
        down vote



        accepted






        Using GNU sed:



        sed "s/,/n/3; G" file

        ETRYTUUI,YTYUIL,UIOKJHGFGH
        34567898766


        Explanation💡:



        sed stands for stream editor..sed has the following syntax:



        substitute/match(or pattern)/replacement/position file


        In the above command, s substitute the third , by a new line n.



        G is to append a new line to the contents of the pattern space and then append the contents of the hold space to the pattern space.






        share|improve this answer














        Using GNU sed:



        sed "s/,/n/3; G" file

        ETRYTUUI,YTYUIL,UIOKJHGFGH
        34567898766


        Explanation💡:



        sed stands for stream editor..sed has the following syntax:



        substitute/match(or pattern)/replacement/position file


        In the above command, s substitute the third , by a new line n.



        G is to append a new line to the contents of the pattern space and then append the contents of the hold space to the pattern space.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 hours ago

























        answered 20 hours ago









        Goro

        8,68754384




        8,68754384







        • 2




          It would be great if you could add a short explanation of how this works for users who don't know sed well.
          – terdon♦
          5 hours ago












        • 2




          It would be great if you could add a short explanation of how this works for users who don't know sed well.
          – terdon♦
          5 hours ago







        2




        2




        It would be great if you could add a short explanation of how this works for users who don't know sed well.
        – terdon♦
        5 hours ago




        It would be great if you could add a short explanation of how this works for users who don't know sed well.
        – terdon♦
        5 hours ago












        up vote
        8
        down vote













        awk -F, -vOFS=, 'print $1,$2,$3; print $4; print ""' file


        will produce your desired output






        share|improve this answer
























          up vote
          8
          down vote













          awk -F, -vOFS=, 'print $1,$2,$3; print $4; print ""' file


          will produce your desired output






          share|improve this answer






















            up vote
            8
            down vote










            up vote
            8
            down vote









            awk -F, -vOFS=, 'print $1,$2,$3; print $4; print ""' file


            will produce your desired output






            share|improve this answer












            awk -F, -vOFS=, 'print $1,$2,$3; print $4; print ""' file


            will produce your desired output







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 20 hours ago









            glenn jackman

            48.9k466105




            48.9k466105




















                up vote
                3
                down vote













                A few Perl approaches:



                $ perl -pe 's/,([^,]+)$/n$1n/' file
                AKJHGFGUIKL,OIUYT,KJHBTYUI
                98765434567

                RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
                6789876

                ETRYTUUI,YTYUIL,UIOKJHGFGH
                34567898766


                The -p means "read the input file line by line and print each line after applying the script given by -e to it". The s/foo/bar/ is the substitution operator which will replace foo with bar. Here, we are matching a comma followed by one or more non-comma characters ([^,]+) until the end of the line ($). The parentheses around the ([^,]+) will "capture" whatever is matched so we can refer to it as $1 on the right hand side of the operator. Therefore, this will replace the text after the last comma with a newline, then the matched text and then another newline.



                If you can't be sure the third comma is the last one, you can do:



                perl -pe 's/([^,]+,)3K(.+)/n$2n/' file


                or



                perl -pe 's/(.+?,.+?,.+?),(.+)/$1n$2n/' file


                And here are some more, just for fun:



                perl -pe 's/([^,]+,)3K(.+)/n$2n/' file
                perl -F, -pe '$k=pop(@F); $_=join(",", @F)."n$kn"' file
                perl -F, -le 'print join ",", @F[0..2],"n@F[3..$#F]n"' file





                share|improve this answer
























                  up vote
                  3
                  down vote













                  A few Perl approaches:



                  $ perl -pe 's/,([^,]+)$/n$1n/' file
                  AKJHGFGUIKL,OIUYT,KJHBTYUI
                  98765434567

                  RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
                  6789876

                  ETRYTUUI,YTYUIL,UIOKJHGFGH
                  34567898766


                  The -p means "read the input file line by line and print each line after applying the script given by -e to it". The s/foo/bar/ is the substitution operator which will replace foo with bar. Here, we are matching a comma followed by one or more non-comma characters ([^,]+) until the end of the line ($). The parentheses around the ([^,]+) will "capture" whatever is matched so we can refer to it as $1 on the right hand side of the operator. Therefore, this will replace the text after the last comma with a newline, then the matched text and then another newline.



                  If you can't be sure the third comma is the last one, you can do:



                  perl -pe 's/([^,]+,)3K(.+)/n$2n/' file


                  or



                  perl -pe 's/(.+?,.+?,.+?),(.+)/$1n$2n/' file


                  And here are some more, just for fun:



                  perl -pe 's/([^,]+,)3K(.+)/n$2n/' file
                  perl -F, -pe '$k=pop(@F); $_=join(",", @F)."n$kn"' file
                  perl -F, -le 'print join ",", @F[0..2],"n@F[3..$#F]n"' file





                  share|improve this answer






















                    up vote
                    3
                    down vote










                    up vote
                    3
                    down vote









                    A few Perl approaches:



                    $ perl -pe 's/,([^,]+)$/n$1n/' file
                    AKJHGFGUIKL,OIUYT,KJHBTYUI
                    98765434567

                    RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
                    6789876

                    ETRYTUUI,YTYUIL,UIOKJHGFGH
                    34567898766


                    The -p means "read the input file line by line and print each line after applying the script given by -e to it". The s/foo/bar/ is the substitution operator which will replace foo with bar. Here, we are matching a comma followed by one or more non-comma characters ([^,]+) until the end of the line ($). The parentheses around the ([^,]+) will "capture" whatever is matched so we can refer to it as $1 on the right hand side of the operator. Therefore, this will replace the text after the last comma with a newline, then the matched text and then another newline.



                    If you can't be sure the third comma is the last one, you can do:



                    perl -pe 's/([^,]+,)3K(.+)/n$2n/' file


                    or



                    perl -pe 's/(.+?,.+?,.+?),(.+)/$1n$2n/' file


                    And here are some more, just for fun:



                    perl -pe 's/([^,]+,)3K(.+)/n$2n/' file
                    perl -F, -pe '$k=pop(@F); $_=join(",", @F)."n$kn"' file
                    perl -F, -le 'print join ",", @F[0..2],"n@F[3..$#F]n"' file





                    share|improve this answer












                    A few Perl approaches:



                    $ perl -pe 's/,([^,]+)$/n$1n/' file
                    AKJHGFGUIKL,OIUYT,KJHBTYUI
                    98765434567

                    RTYUIKHGFGH,TYUJI,TGHYJKJKLJKL
                    6789876

                    ETRYTUUI,YTYUIL,UIOKJHGFGH
                    34567898766


                    The -p means "read the input file line by line and print each line after applying the script given by -e to it". The s/foo/bar/ is the substitution operator which will replace foo with bar. Here, we are matching a comma followed by one or more non-comma characters ([^,]+) until the end of the line ($). The parentheses around the ([^,]+) will "capture" whatever is matched so we can refer to it as $1 on the right hand side of the operator. Therefore, this will replace the text after the last comma with a newline, then the matched text and then another newline.



                    If you can't be sure the third comma is the last one, you can do:



                    perl -pe 's/([^,]+,)3K(.+)/n$2n/' file


                    or



                    perl -pe 's/(.+?,.+?,.+?),(.+)/$1n$2n/' file


                    And here are some more, just for fun:



                    perl -pe 's/([^,]+,)3K(.+)/n$2n/' file
                    perl -F, -pe '$k=pop(@F); $_=join(",", @F)."n$kn"' file
                    perl -F, -le 'print join ",", @F[0..2],"n@F[3..$#F]n"' file






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 5 hours ago









                    terdon♦

                    124k29234412




                    124k29234412




















                        up vote
                        2
                        down vote













                        awk -F, 'print $1, $2, $3,"n"$4'





                        share|improve this answer
















                        • 2




                          You'd need to set OFS=, as well in order to preserve the other delimiters
                          – steeldriver
                          20 hours ago










                        • @steeldriver but it will not remove the third comma as requested?
                          – TNT
                          20 hours ago











                        • ... then change the last part to a simple concatenation $3 "n" $4
                          – steeldriver
                          20 hours ago











                        • This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
                          – terdon♦
                          5 hours ago














                        up vote
                        2
                        down vote













                        awk -F, 'print $1, $2, $3,"n"$4'





                        share|improve this answer
















                        • 2




                          You'd need to set OFS=, as well in order to preserve the other delimiters
                          – steeldriver
                          20 hours ago










                        • @steeldriver but it will not remove the third comma as requested?
                          – TNT
                          20 hours ago











                        • ... then change the last part to a simple concatenation $3 "n" $4
                          – steeldriver
                          20 hours ago











                        • This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
                          – terdon♦
                          5 hours ago












                        up vote
                        2
                        down vote










                        up vote
                        2
                        down vote









                        awk -F, 'print $1, $2, $3,"n"$4'





                        share|improve this answer












                        awk -F, 'print $1, $2, $3,"n"$4'






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 20 hours ago









                        TNT

                        363313




                        363313







                        • 2




                          You'd need to set OFS=, as well in order to preserve the other delimiters
                          – steeldriver
                          20 hours ago










                        • @steeldriver but it will not remove the third comma as requested?
                          – TNT
                          20 hours ago











                        • ... then change the last part to a simple concatenation $3 "n" $4
                          – steeldriver
                          20 hours ago











                        • This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
                          – terdon♦
                          5 hours ago












                        • 2




                          You'd need to set OFS=, as well in order to preserve the other delimiters
                          – steeldriver
                          20 hours ago










                        • @steeldriver but it will not remove the third comma as requested?
                          – TNT
                          20 hours ago











                        • ... then change the last part to a simple concatenation $3 "n" $4
                          – steeldriver
                          20 hours ago











                        • This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
                          – terdon♦
                          5 hours ago







                        2




                        2




                        You'd need to set OFS=, as well in order to preserve the other delimiters
                        – steeldriver
                        20 hours ago




                        You'd need to set OFS=, as well in order to preserve the other delimiters
                        – steeldriver
                        20 hours ago












                        @steeldriver but it will not remove the third comma as requested?
                        – TNT
                        20 hours ago





                        @steeldriver but it will not remove the third comma as requested?
                        – TNT
                        20 hours ago













                        ... then change the last part to a simple concatenation $3 "n" $4
                        – steeldriver
                        20 hours ago





                        ... then change the last part to a simple concatenation $3 "n" $4
                        – steeldriver
                        20 hours ago













                        This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
                        – terdon♦
                        5 hours ago




                        This removes all commas, replacing them with spaces and doesn't add the extra newline between records. Please make sure your output is the same as the desired output shown in the question.
                        – terdon♦
                        5 hours ago










                        up vote
                        1
                        down vote













                        Alternative less succinct sed code:



                        sed 's/,([^,]*)/n1n/3' file


                        ...which can be used if the hold buffer were needed for some other purpose, (supposing some additional requirement). If you need portable code (the above is gnu sed syntax) use literal newlines in the RHS:



                        sed 's/,([^,]*)/
                        1
                        /3' file





                        share|improve this answer


























                          up vote
                          1
                          down vote













                          Alternative less succinct sed code:



                          sed 's/,([^,]*)/n1n/3' file


                          ...which can be used if the hold buffer were needed for some other purpose, (supposing some additional requirement). If you need portable code (the above is gnu sed syntax) use literal newlines in the RHS:



                          sed 's/,([^,]*)/
                          1
                          /3' file





                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote









                            Alternative less succinct sed code:



                            sed 's/,([^,]*)/n1n/3' file


                            ...which can be used if the hold buffer were needed for some other purpose, (supposing some additional requirement). If you need portable code (the above is gnu sed syntax) use literal newlines in the RHS:



                            sed 's/,([^,]*)/
                            1
                            /3' file





                            share|improve this answer














                            Alternative less succinct sed code:



                            sed 's/,([^,]*)/n1n/3' file


                            ...which can be used if the hold buffer were needed for some other purpose, (supposing some additional requirement). If you need portable code (the above is gnu sed syntax) use literal newlines in the RHS:



                            sed 's/,([^,]*)/
                            1
                            /3' file






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 10 mins ago









                            don_crissti

                            47.7k15126155




                            47.7k15126155










                            answered 2 hours ago









                            agc

                            4,3571935




                            4,3571935




















                                Simon Q is a new contributor. Be nice, and check out our Code of Conduct.









                                 

                                draft saved


                                draft discarded


















                                Simon Q is a new contributor. Be nice, and check out our Code of Conduct.












                                Simon Q is a new contributor. Be nice, and check out our Code of Conduct.











                                Simon Q is a new contributor. Be nice, and check out our Code of Conduct.













                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f474882%2freplace-the-third-comma-on-each-line-with-newline%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                What does second last employer means? [closed]

                                Installing NextGIS Connect into QGIS 3?

                                One-line joke