AWK: Print first field of every line as identifier for every following field in the corresponding line












0














I have a input file like this with a blank as field seperator



AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2


The output should look like this:



AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....


The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.










share|improve this question






















  • Really close to a duplicate: unix.stackexchange.com/q/456907/117549
    – Jeff Schaller
    48 mins ago
















0














I have a input file like this with a blank as field seperator



AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2


The output should look like this:



AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....


The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.










share|improve this question






















  • Really close to a duplicate: unix.stackexchange.com/q/456907/117549
    – Jeff Schaller
    48 mins ago














0












0








0







I have a input file like this with a blank as field seperator



AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2


The output should look like this:



AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....


The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.










share|improve this question













I have a input file like this with a blank as field seperator



AAABBB: 243.234.12.2 123.3.2 231.5.12 451.192.29.9
BBXDS: 324.22.32.5 235.235.283 234.239. 234.23.23.1
DDF: 23.12.59.09 98.39.239.29 394.293.2.2


The output should look like this:



AAABBB: 243.234.12.2
AAABBB: 123.3.2
AAABBB: 231.5.12
AAABBB: 451.192.29.9
BBXDS: 324.22.32.5
BBXDS: 235.235.283
BBXDS: 234.239.
.....


The first field of every line is a identifier and should be printed as a new line in front of every column in the corresponding line until the end of the line.







awk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 56 mins ago









T-One

586




586












  • Really close to a duplicate: unix.stackexchange.com/q/456907/117549
    – Jeff Schaller
    48 mins ago


















  • Really close to a duplicate: unix.stackexchange.com/q/456907/117549
    – Jeff Schaller
    48 mins ago
















Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago




Really close to a duplicate: unix.stackexchange.com/q/456907/117549
– Jeff Schaller
48 mins ago










1 Answer
1






active

oldest

votes


















4














Fairly straightforwardly:



awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input


On every line, oop from 2 until the last field (Number of Fields), printing field 1 and the looped field.






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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f491333%2fawk-print-first-field-of-every-line-as-identifier-for-every-following-field-in%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    Fairly straightforwardly:



    awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input


    On every line, oop from 2 until the last field (Number of Fields), printing field 1 and the looped field.






    share|improve this answer


























      4














      Fairly straightforwardly:



      awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input


      On every line, oop from 2 until the last field (Number of Fields), printing field 1 and the looped field.






      share|improve this answer
























        4












        4








        4






        Fairly straightforwardly:



        awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input


        On every line, oop from 2 until the last field (Number of Fields), printing field 1 and the looped field.






        share|improve this answer












        Fairly straightforwardly:



        awk '{ for(i=2; i <= NF; i++) print $1, $i}' < input


        On every line, oop from 2 until the last field (Number of Fields), printing field 1 and the looped field.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 50 mins ago









        Jeff Schaller

        38.7k1053125




        38.7k1053125






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491333%2fawk-print-first-field-of-every-line-as-identifier-for-every-following-field-in%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            サソリ

            広島県道265号伴広島線

            Setup Asymptote in Texstudio