print value from first line on each line

Multi tool use
Multi tool use

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











up vote
5
down vote

favorite












I have file of following format:



 1.0
2.0
3.0
4.0
5.0


Is it possible to copy value in first line 1.0 to the beginning of every line in awk? Like this:



 1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0






share|improve this question






















  • With GNU sed: sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file In this case, awk is more transparent.
    – Cyrus
    Dec 25 '17 at 11:31















up vote
5
down vote

favorite












I have file of following format:



 1.0
2.0
3.0
4.0
5.0


Is it possible to copy value in first line 1.0 to the beginning of every line in awk? Like this:



 1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0






share|improve this question






















  • With GNU sed: sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file In this case, awk is more transparent.
    – Cyrus
    Dec 25 '17 at 11:31













up vote
5
down vote

favorite









up vote
5
down vote

favorite











I have file of following format:



 1.0
2.0
3.0
4.0
5.0


Is it possible to copy value in first line 1.0 to the beginning of every line in awk? Like this:



 1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0






share|improve this question














I have file of following format:



 1.0
2.0
3.0
4.0
5.0


Is it possible to copy value in first line 1.0 to the beginning of every line in awk? Like this:



 1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0








share|improve this question













share|improve this question




share|improve this question








edited Dec 25 '17 at 11:21









Jeff Schaller

31.8k848109




31.8k848109










asked Dec 25 '17 at 7:43









Bhavin Chirag

1514




1514











  • With GNU sed: sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file In this case, awk is more transparent.
    – Cyrus
    Dec 25 '17 at 11:31

















  • With GNU sed: sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file In this case, awk is more transparent.
    – Cyrus
    Dec 25 '17 at 11:31
















With GNU sed: sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file In this case, awk is more transparent.
– Cyrus
Dec 25 '17 at 11:31





With GNU sed: sed -n '1h;G;s/n/ /p; :j;g;N;s/n/ /p;bj' file In this case, awk is more transparent.
– Cyrus
Dec 25 '17 at 11:31











2 Answers
2






active

oldest

votes

















up vote
8
down vote



accepted










awk 'NR==1 f=$1 print f,$1' file


Output:




1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0


If current line number (NR) is 1 then save column 1 ($1) to variable f. For every line print content of variable f and content of column 1.






share|improve this answer






















  • i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
    – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
    Dec 25 '17 at 7:56

















up vote
1
down vote













I have done this by sed command working as expected




k=`sed -n 1p file`;sed "s/^/$k /g" file



output




1.0 1.0
1.0 2.0
1.0 3.0
1.0 4.0
1.0 5.0







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%2f412906%2fprint-value-from-first-line-on-each-line%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
    8
    down vote



    accepted










    awk 'NR==1 f=$1 print f,$1' file


    Output:




    1.0 1.0
    1.0 2.0
    1.0 3.0
    1.0 4.0
    1.0 5.0


    If current line number (NR) is 1 then save column 1 ($1) to variable f. For every line print content of variable f and content of column 1.






    share|improve this answer






















    • i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
      – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
      Dec 25 '17 at 7:56














    up vote
    8
    down vote



    accepted










    awk 'NR==1 f=$1 print f,$1' file


    Output:




    1.0 1.0
    1.0 2.0
    1.0 3.0
    1.0 4.0
    1.0 5.0


    If current line number (NR) is 1 then save column 1 ($1) to variable f. For every line print content of variable f and content of column 1.






    share|improve this answer






















    • i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
      – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
      Dec 25 '17 at 7:56












    up vote
    8
    down vote



    accepted







    up vote
    8
    down vote



    accepted






    awk 'NR==1 f=$1 print f,$1' file


    Output:




    1.0 1.0
    1.0 2.0
    1.0 3.0
    1.0 4.0
    1.0 5.0


    If current line number (NR) is 1 then save column 1 ($1) to variable f. For every line print content of variable f and content of column 1.






    share|improve this answer














    awk 'NR==1 f=$1 print f,$1' file


    Output:




    1.0 1.0
    1.0 2.0
    1.0 3.0
    1.0 4.0
    1.0 5.0


    If current line number (NR) is 1 then save column 1 ($1) to variable f. For every line print content of variable f and content of column 1.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 25 '17 at 9:00

























    answered Dec 25 '17 at 7:55









    Cyrus

    7,0362835




    7,0362835











    • i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
      – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
      Dec 25 '17 at 7:56
















    • i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
      – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
      Dec 25 '17 at 7:56















    i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
    – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
    Dec 25 '17 at 7:56




    i though like you ! lol but he want different thing. :D i edited my answer to achieve his target.
    – Î±Ô‹É±Ò½Ôƒ αмєяιcαη
    Dec 25 '17 at 7:56












    up vote
    1
    down vote













    I have done this by sed command working as expected




    k=`sed -n 1p file`;sed "s/^/$k /g" file



    output




    1.0 1.0
    1.0 2.0
    1.0 3.0
    1.0 4.0
    1.0 5.0







    share|improve this answer
























      up vote
      1
      down vote













      I have done this by sed command working as expected




      k=`sed -n 1p file`;sed "s/^/$k /g" file



      output




      1.0 1.0
      1.0 2.0
      1.0 3.0
      1.0 4.0
      1.0 5.0







      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        I have done this by sed command working as expected




        k=`sed -n 1p file`;sed "s/^/$k /g" file



        output




        1.0 1.0
        1.0 2.0
        1.0 3.0
        1.0 4.0
        1.0 5.0







        share|improve this answer












        I have done this by sed command working as expected




        k=`sed -n 1p file`;sed "s/^/$k /g" file



        output




        1.0 1.0
        1.0 2.0
        1.0 3.0
        1.0 4.0
        1.0 5.0








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 25 '17 at 9:28









        Praveen Kumar BS

        1,010128




        1,010128






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412906%2fprint-value-from-first-line-on-each-line%23new-answer', 'question_page');

            );

            Post as a guest













































































            Rl3BsnyVTO FmtzsD9 mlnKxDXBPsXHm,2sy,5,hAMEAVh7mOUL2Vw,f,gE TP,VOsbsd2,XQYWSkbHa2PW
            F8z4S,a95VZ4A d53tcjtJc,1,R,pyoQDZFx5S4D afBIOt l,tCgyGUGscyastJRn,BCYJVp,t6ETfiRaPL711Hv O8n hsp 2g7K9xzT,Z,D

            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            How many registers does an x86_64 CPU actually have?

            Displaying single band from multi-band raster using QGIS