how to separate line using awk

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











up vote
2
down vote

favorite












How can I separate the line as below in a csv file:



(12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


to the below as 2 different rows:



(12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


I tried using:



awk -F"[()]" 'print $2' test.csv 


but it didn't work and lost a few rows.



This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator







share|improve this question


























    up vote
    2
    down vote

    favorite












    How can I separate the line as below in a csv file:



    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


    to the below as 2 different rows:



    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


    I tried using:



    awk -F"[()]" 'print $2' test.csv 


    but it didn't work and lost a few rows.



    This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      How can I separate the line as below in a csv file:



      (12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


      to the below as 2 different rows:



      (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
      (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


      I tried using:



      awk -F"[()]" 'print $2' test.csv 


      but it didn't work and lost a few rows.



      This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator







      share|improve this question














      How can I separate the line as below in a csv file:



      (12,'hello','this girl,is lovely(adorable rn actually)',goodbye),(13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


      to the below as 2 different rows:



      (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
      (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


      I tried using:



      awk -F"[()]" 'print $2' test.csv 


      but it didn't work and lost a few rows.



      This data is actually a SQL query and I need to extract the data and convert it into different rows using the comma after ) and before ( as row seperator









      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 22 at 1:29

























      asked Jan 22 at 1:22









      Derek

      133




      133




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          This awk command can do what you want:



          awk -F '),' ' print $1")" "n" $2' source.csv


          Result:



          (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
          (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)





          share|improve this answer



























            up vote
            2
            down vote













            With GNU sed (and your sample input saved in a file called ./input):



            $ sed -e 's/),(/)n(/g' ./input
            (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
            (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


            This changes the comma in every ),( to a newline.



            WARNING: If that character sequence occurs inside your actual data, it will be changed there too.



            You could do the same in awk, but there's little or no advantage over using sed:



            $ awk 'gsub(/),(/,")n(",$0)' ./input
            (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
            (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


            Unless you're going to do further processing on the input line that requires awk features, just use sed.






            share|improve this answer




















            • Thanks alot for your help..really appreciate it! thanks :)
              – Derek
              Jan 22 at 18:54










            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%2f418721%2fhow-to-separate-line-using-awk%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            This awk command can do what you want:



            awk -F '),' ' print $1")" "n" $2' source.csv


            Result:



            (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
            (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)





            share|improve this answer
























              up vote
              1
              down vote



              accepted










              This awk command can do what you want:



              awk -F '),' ' print $1")" "n" $2' source.csv


              Result:



              (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
              (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)





              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                This awk command can do what you want:



                awk -F '),' ' print $1")" "n" $2' source.csv


                Result:



                (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)





                share|improve this answer












                This awk command can do what you want:



                awk -F '),' ' print $1")" "n" $2' source.csv


                Result:



                (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 22 at 5:35









                George Udosen

                1,112318




                1,112318






















                    up vote
                    2
                    down vote













                    With GNU sed (and your sample input saved in a file called ./input):



                    $ sed -e 's/),(/)n(/g' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    This changes the comma in every ),( to a newline.



                    WARNING: If that character sequence occurs inside your actual data, it will be changed there too.



                    You could do the same in awk, but there's little or no advantage over using sed:



                    $ awk 'gsub(/),(/,")n(",$0)' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    Unless you're going to do further processing on the input line that requires awk features, just use sed.






                    share|improve this answer




















                    • Thanks alot for your help..really appreciate it! thanks :)
                      – Derek
                      Jan 22 at 18:54














                    up vote
                    2
                    down vote













                    With GNU sed (and your sample input saved in a file called ./input):



                    $ sed -e 's/),(/)n(/g' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    This changes the comma in every ),( to a newline.



                    WARNING: If that character sequence occurs inside your actual data, it will be changed there too.



                    You could do the same in awk, but there's little or no advantage over using sed:



                    $ awk 'gsub(/),(/,")n(",$0)' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    Unless you're going to do further processing on the input line that requires awk features, just use sed.






                    share|improve this answer




















                    • Thanks alot for your help..really appreciate it! thanks :)
                      – Derek
                      Jan 22 at 18:54












                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    With GNU sed (and your sample input saved in a file called ./input):



                    $ sed -e 's/),(/)n(/g' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    This changes the comma in every ),( to a newline.



                    WARNING: If that character sequence occurs inside your actual data, it will be changed there too.



                    You could do the same in awk, but there's little or no advantage over using sed:



                    $ awk 'gsub(/),(/,")n(",$0)' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    Unless you're going to do further processing on the input line that requires awk features, just use sed.






                    share|improve this answer












                    With GNU sed (and your sample input saved in a file called ./input):



                    $ sed -e 's/),(/)n(/g' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    This changes the comma in every ),( to a newline.



                    WARNING: If that character sequence occurs inside your actual data, it will be changed there too.



                    You could do the same in awk, but there's little or no advantage over using sed:



                    $ awk 'gsub(/),(/,")n(",$0)' ./input
                    (12,'hello','this girl,is lovely(adorable rn actually)',goodbye)
                    (13,'hello','this fruit,is super tasty (sweet actually)',goodbye)


                    Unless you're going to do further processing on the input line that requires awk features, just use sed.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 22 at 2:53









                    cas

                    37.7k44393




                    37.7k44393











                    • Thanks alot for your help..really appreciate it! thanks :)
                      – Derek
                      Jan 22 at 18:54
















                    • Thanks alot for your help..really appreciate it! thanks :)
                      – Derek
                      Jan 22 at 18:54















                    Thanks alot for your help..really appreciate it! thanks :)
                    – Derek
                    Jan 22 at 18:54




                    Thanks alot for your help..really appreciate it! thanks :)
                    – Derek
                    Jan 22 at 18:54












                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f418721%2fhow-to-separate-line-using-awk%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