Preformat output CSV

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











up vote
4
down vote

favorite
1












I have a script bash that converts this file "origin.txt"



cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z


to



cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z


How could I do it in bash with AWK?







share|improve this question

















  • 3




    So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like paste -d, - - - < origin.txt or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
    – steeldriver
    Aug 6 at 16:56















up vote
4
down vote

favorite
1












I have a script bash that converts this file "origin.txt"



cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z


to



cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z


How could I do it in bash with AWK?







share|improve this question

















  • 3




    So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like paste -d, - - - < origin.txt or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
    – steeldriver
    Aug 6 at 16:56













up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I have a script bash that converts this file "origin.txt"



cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z


to



cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z


How could I do it in bash with AWK?







share|improve this question













I have a script bash that converts this file "origin.txt"



cxx-yyy-zzz-999-111
2018-01-1T00:10:54.412Z
2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt
2018-01-1T00:41:38.867Z
2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123
2018-01-1T00:12:37.152Z
2018-01-5T00:12:44.307Z


to



cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z


How could I do it in bash with AWK?









share|improve this question












share|improve this question




share|improve this question








edited Aug 6 at 17:08









SivaPrasath

3,68311636




3,68311636









asked Aug 6 at 15:15









kdetony

211




211







  • 3




    So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like paste -d, - - - < origin.txt or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
    – steeldriver
    Aug 6 at 16:56













  • 3




    So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like paste -d, - - - < origin.txt or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
    – steeldriver
    Aug 6 at 16:56








3




3




So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like paste -d, - - - < origin.txt or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
– steeldriver
Aug 6 at 16:56





So what's the rule being applied here? if you just want to take lines 3 at a time I'd use something like paste -d, - - - < origin.txt or (if you insist on awk) awk 'ORS="n" NR%3 ORS="," 1' origin.txt
– steeldriver
Aug 6 at 16:56











2 Answers
2






active

oldest

votes

















up vote
4
down vote













Using sed:



sed 'N;N;s/n/,/g' origin.txt 


Using awk:



awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt 


Output:



cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z





share|improve this answer




























    up vote
    3
    down vote













    I have an awk script file named tmp.awk with the following contents



    BEGIN 
    i=0


    if (i==0)
    f1=$0
    i++
    else if (i==1)
    f2=$0
    i++
    else
    i=0
    print f1","f2","$0




    And a file origin.txt with the following contents



    cxx-yyy-zzz-999-111
    2018-01-1T00:10:54.412Z
    2018-01-5T00:01:19.447Z
    1111-6b54-eeee-rrrr-tttt
    2018-01-1T00:41:38.867Z
    2018-01-5T01:14:55.744Z
    1234456-1233-6666-mmmm-12123
    2018-01-1T00:12:37.152Z
    2018-01-5T00:12:44.307Z


    Here is my awk command and sample output.



    zb@server ~ $ awk -f tmp.awk origin.txt 
    cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
    1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
    1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z





    share|improve this answer





















    • thank you very much they gave me several ideas with their eternally grateful examples
      – kdetony
      2 days ago










    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%2f460845%2fpreformat-output-csv%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
    4
    down vote













    Using sed:



    sed 'N;N;s/n/,/g' origin.txt 


    Using awk:



    awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt 


    Output:



    cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
    1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
    1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z





    share|improve this answer

























      up vote
      4
      down vote













      Using sed:



      sed 'N;N;s/n/,/g' origin.txt 


      Using awk:



      awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt 


      Output:



      cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
      1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
      1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z





      share|improve this answer























        up vote
        4
        down vote










        up vote
        4
        down vote









        Using sed:



        sed 'N;N;s/n/,/g' origin.txt 


        Using awk:



        awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt 


        Output:



        cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
        1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
        1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z





        share|improve this answer













        Using sed:



        sed 'N;N;s/n/,/g' origin.txt 


        Using awk:



        awk ' printf "%s", $0; if (NR % 3 == 0) print ""; else printf "," ' origin.txt 


        Output:



        cxx-yyy-zzz-999-111 2018-01-1T00:10:54.412Z 2018-01-5T00:01:19.447Z
        1111-6b54-eeee-rrrr-tttt 2018-01-1T00:41:38.867Z 2018-01-5T01:14:55.744Z
        1234456-1233-6666-mmmm-12123 2018-01-1T00:12:37.152Z 2018-01-5T00:12:44.307Z






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Aug 6 at 17:04









        SivaPrasath

        3,68311636




        3,68311636






















            up vote
            3
            down vote













            I have an awk script file named tmp.awk with the following contents



            BEGIN 
            i=0


            if (i==0)
            f1=$0
            i++
            else if (i==1)
            f2=$0
            i++
            else
            i=0
            print f1","f2","$0




            And a file origin.txt with the following contents



            cxx-yyy-zzz-999-111
            2018-01-1T00:10:54.412Z
            2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt
            2018-01-1T00:41:38.867Z
            2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123
            2018-01-1T00:12:37.152Z
            2018-01-5T00:12:44.307Z


            Here is my awk command and sample output.



            zb@server ~ $ awk -f tmp.awk origin.txt 
            cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z





            share|improve this answer





















            • thank you very much they gave me several ideas with their eternally grateful examples
              – kdetony
              2 days ago














            up vote
            3
            down vote













            I have an awk script file named tmp.awk with the following contents



            BEGIN 
            i=0


            if (i==0)
            f1=$0
            i++
            else if (i==1)
            f2=$0
            i++
            else
            i=0
            print f1","f2","$0




            And a file origin.txt with the following contents



            cxx-yyy-zzz-999-111
            2018-01-1T00:10:54.412Z
            2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt
            2018-01-1T00:41:38.867Z
            2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123
            2018-01-1T00:12:37.152Z
            2018-01-5T00:12:44.307Z


            Here is my awk command and sample output.



            zb@server ~ $ awk -f tmp.awk origin.txt 
            cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z





            share|improve this answer





















            • thank you very much they gave me several ideas with their eternally grateful examples
              – kdetony
              2 days ago












            up vote
            3
            down vote










            up vote
            3
            down vote









            I have an awk script file named tmp.awk with the following contents



            BEGIN 
            i=0


            if (i==0)
            f1=$0
            i++
            else if (i==1)
            f2=$0
            i++
            else
            i=0
            print f1","f2","$0




            And a file origin.txt with the following contents



            cxx-yyy-zzz-999-111
            2018-01-1T00:10:54.412Z
            2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt
            2018-01-1T00:41:38.867Z
            2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123
            2018-01-1T00:12:37.152Z
            2018-01-5T00:12:44.307Z


            Here is my awk command and sample output.



            zb@server ~ $ awk -f tmp.awk origin.txt 
            cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z





            share|improve this answer













            I have an awk script file named tmp.awk with the following contents



            BEGIN 
            i=0


            if (i==0)
            f1=$0
            i++
            else if (i==1)
            f2=$0
            i++
            else
            i=0
            print f1","f2","$0




            And a file origin.txt with the following contents



            cxx-yyy-zzz-999-111
            2018-01-1T00:10:54.412Z
            2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt
            2018-01-1T00:41:38.867Z
            2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123
            2018-01-1T00:12:37.152Z
            2018-01-5T00:12:44.307Z


            Here is my awk command and sample output.



            zb@server ~ $ awk -f tmp.awk origin.txt 
            cxx-yyy-zzz-999-111,2018-01-1T00:10:54.412Z,2018-01-5T00:01:19.447Z
            1111-6b54-eeee-rrrr-tttt,2018-01-1T00:41:38.867Z,2018-01-5T01:14:55.744Z
            1234456-1233-6666-mmmm-12123,2018-01-1T00:12:37.152Z,2018-01-5T00:12:44.307Z






            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Aug 6 at 16:37









            Zachary Brady

            3,376831




            3,376831











            • thank you very much they gave me several ideas with their eternally grateful examples
              – kdetony
              2 days ago
















            • thank you very much they gave me several ideas with their eternally grateful examples
              – kdetony
              2 days ago















            thank you very much they gave me several ideas with their eternally grateful examples
            – kdetony
            2 days ago




            thank you very much they gave me several ideas with their eternally grateful examples
            – kdetony
            2 days ago












             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460845%2fpreformat-output-csv%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