how to divide two columns from two different text files in bash

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











up vote
1
down vote

favorite












I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.



declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt









share|improve this question







New contributor




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



















  • Are you looking for paste? paste File1.txt File2.txt
    – unxnut
    8 mins ago














up vote
1
down vote

favorite












I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.



declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt









share|improve this question







New contributor




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



















  • Are you looking for paste? paste File1.txt File2.txt
    – unxnut
    8 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.



declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt









share|improve this question







New contributor




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











I have two text files each contains a column of numbers.
How can I divide this two columns element vise and save the new column in a new text file? I tried this but it didn't work.



declare -a col1
declare -a col2
col1=`awk 'print $1' File1.txt`
col2=`awk 'print $1' File2.txt`
awk 'print $File1/$File2 > File3.txt






shell-script






share|improve this question







New contributor




user3708408 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




user3708408 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






New contributor




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









asked 14 mins ago









user3708408

61




61




New contributor




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





New contributor





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






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











  • Are you looking for paste? paste File1.txt File2.txt
    – unxnut
    8 mins ago
















  • Are you looking for paste? paste File1.txt File2.txt
    – unxnut
    8 mins ago















Are you looking for paste? paste File1.txt File2.txt
– unxnut
8 mins ago




Are you looking for paste? paste File1.txt File2.txt
– unxnut
8 mins ago










1 Answer
1






active

oldest

votes

















up vote
0
down vote













If what you mean by divide is the mathematical division operation, then try this:



paste inf1 inf2 | awk 'print($1/$2)'


That's assuming that inf1 and inf2 are two files with one column of numbers, something like:



$ seq 10 30 > inf1
$ seq 2 22 > inf2
$ paste inf1 inf2 | awk 'print($1/$2)'
5
3.66667
3
2.6
2.33333
2.14286
2
1.88889
1.8
1.72727
1.66667
1.61538
1.57143
1.53333
1.5
1.47059
1.44444
1.42105
1.4
1.38095
1.36364


If you need an specific format then use printf instead of print.





share




















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



    );






    user3708408 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%2f478571%2fhow-to-divide-two-columns-from-two-different-text-files-in-bash%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    If what you mean by divide is the mathematical division operation, then try this:



    paste inf1 inf2 | awk 'print($1/$2)'


    That's assuming that inf1 and inf2 are two files with one column of numbers, something like:



    $ seq 10 30 > inf1
    $ seq 2 22 > inf2
    $ paste inf1 inf2 | awk 'print($1/$2)'
    5
    3.66667
    3
    2.6
    2.33333
    2.14286
    2
    1.88889
    1.8
    1.72727
    1.66667
    1.61538
    1.57143
    1.53333
    1.5
    1.47059
    1.44444
    1.42105
    1.4
    1.38095
    1.36364


    If you need an specific format then use printf instead of print.





    share
























      up vote
      0
      down vote













      If what you mean by divide is the mathematical division operation, then try this:



      paste inf1 inf2 | awk 'print($1/$2)'


      That's assuming that inf1 and inf2 are two files with one column of numbers, something like:



      $ seq 10 30 > inf1
      $ seq 2 22 > inf2
      $ paste inf1 inf2 | awk 'print($1/$2)'
      5
      3.66667
      3
      2.6
      2.33333
      2.14286
      2
      1.88889
      1.8
      1.72727
      1.66667
      1.61538
      1.57143
      1.53333
      1.5
      1.47059
      1.44444
      1.42105
      1.4
      1.38095
      1.36364


      If you need an specific format then use printf instead of print.





      share






















        up vote
        0
        down vote










        up vote
        0
        down vote









        If what you mean by divide is the mathematical division operation, then try this:



        paste inf1 inf2 | awk 'print($1/$2)'


        That's assuming that inf1 and inf2 are two files with one column of numbers, something like:



        $ seq 10 30 > inf1
        $ seq 2 22 > inf2
        $ paste inf1 inf2 | awk 'print($1/$2)'
        5
        3.66667
        3
        2.6
        2.33333
        2.14286
        2
        1.88889
        1.8
        1.72727
        1.66667
        1.61538
        1.57143
        1.53333
        1.5
        1.47059
        1.44444
        1.42105
        1.4
        1.38095
        1.36364


        If you need an specific format then use printf instead of print.





        share












        If what you mean by divide is the mathematical division operation, then try this:



        paste inf1 inf2 | awk 'print($1/$2)'


        That's assuming that inf1 and inf2 are two files with one column of numbers, something like:



        $ seq 10 30 > inf1
        $ seq 2 22 > inf2
        $ paste inf1 inf2 | awk 'print($1/$2)'
        5
        3.66667
        3
        2.6
        2.33333
        2.14286
        2
        1.88889
        1.8
        1.72727
        1.66667
        1.61538
        1.57143
        1.53333
        1.5
        1.47059
        1.44444
        1.42105
        1.4
        1.38095
        1.36364


        If you need an specific format then use printf instead of print.






        share











        share


        share










        answered 4 secs ago









        Isaac

        8,72211242




        8,72211242




















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









             

            draft saved


            draft discarded


















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












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











            user3708408 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%2f478571%2fhow-to-divide-two-columns-from-two-different-text-files-in-bash%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