what is awk '{print $1+0.45 “ ” $2 “ ” $3 }' file1> file2?












3















What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
mean? Does it mean changing a row in the first file and put the new data into the second one?










share|improve this question





























    3















    What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
    mean? Does it mean changing a row in the first file and put the new data into the second one?










    share|improve this question



























      3












      3








      3


      2






      What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
      mean? Does it mean changing a row in the first file and put the new data into the second one?










      share|improve this question
















      What does awk '{print $1+0.45 " " $2 " " $3 }' positionXYZ > positionX0.45YZ
      mean? Does it mean changing a row in the first file and put the new data into the second one?







      awk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 29 '14 at 23:58









      Gilles

      539k12810911606




      539k12810911606










      asked Jan 29 '14 at 21:49









      MevaMeva

      1032310




      1032310






















          3 Answers
          3






          active

          oldest

          votes


















          9














          Let's break this down. awk '{foo}' file will apply the expression foo to each line of file and print the result to the terminal (standard output). awk splits its input lines on white space (by default) and saves each field as $1, $2 etc.



          So, the actual expression you are running means: read each input line, add 0.45 to the value of the first field and then print that field as well as the second and third one. This is most easily explained with a simple example:



          $ cat file.txt 
          10 20 30 40
          50 60 70 80

          $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt
          10.45 20 30
          50.45 60 70


          So, as you can see, the awk script added 0.45 to the first field of each line and then printed it along with the second and third. The fourth was ignored since you did not tell it to print $4.



          The next bit has nothing to do with awk, the > symbol is for output redirection and is used by the shell (bash or zsh or whatever you are using). In general command > file will save the output of command in the file file overwriting the contents of the file if it exists and creating it if it does not.



          Putting everything together:



          $ ls
          file.txt

          $ cat file.txt
          10 20 30 40
          50 60 70 80

          $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt > file2.txt

          $ ls
          file2.txt file.txt

          $ cat file2.txt
          10.45 20 30
          50.45 60 70





          share|improve this answer































            1














            file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.



            awk reads each line of file1 and runs the script between {}



            The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...



            The parameters are printed except $1 is added with 0.45






            share|improve this answer

































              0














              $1, $2, $3 mean placeholders of value got at the previous operation.






              share|improve this answer








              New contributor




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




















                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%2f111542%2fwhat-is-awk-print-10-45-2-3-file1-file2%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                9














                Let's break this down. awk '{foo}' file will apply the expression foo to each line of file and print the result to the terminal (standard output). awk splits its input lines on white space (by default) and saves each field as $1, $2 etc.



                So, the actual expression you are running means: read each input line, add 0.45 to the value of the first field and then print that field as well as the second and third one. This is most easily explained with a simple example:



                $ cat file.txt 
                10 20 30 40
                50 60 70 80

                $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt
                10.45 20 30
                50.45 60 70


                So, as you can see, the awk script added 0.45 to the first field of each line and then printed it along with the second and third. The fourth was ignored since you did not tell it to print $4.



                The next bit has nothing to do with awk, the > symbol is for output redirection and is used by the shell (bash or zsh or whatever you are using). In general command > file will save the output of command in the file file overwriting the contents of the file if it exists and creating it if it does not.



                Putting everything together:



                $ ls
                file.txt

                $ cat file.txt
                10 20 30 40
                50 60 70 80

                $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt > file2.txt

                $ ls
                file2.txt file.txt

                $ cat file2.txt
                10.45 20 30
                50.45 60 70





                share|improve this answer




























                  9














                  Let's break this down. awk '{foo}' file will apply the expression foo to each line of file and print the result to the terminal (standard output). awk splits its input lines on white space (by default) and saves each field as $1, $2 etc.



                  So, the actual expression you are running means: read each input line, add 0.45 to the value of the first field and then print that field as well as the second and third one. This is most easily explained with a simple example:



                  $ cat file.txt 
                  10 20 30 40
                  50 60 70 80

                  $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt
                  10.45 20 30
                  50.45 60 70


                  So, as you can see, the awk script added 0.45 to the first field of each line and then printed it along with the second and third. The fourth was ignored since you did not tell it to print $4.



                  The next bit has nothing to do with awk, the > symbol is for output redirection and is used by the shell (bash or zsh or whatever you are using). In general command > file will save the output of command in the file file overwriting the contents of the file if it exists and creating it if it does not.



                  Putting everything together:



                  $ ls
                  file.txt

                  $ cat file.txt
                  10 20 30 40
                  50 60 70 80

                  $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt > file2.txt

                  $ ls
                  file2.txt file.txt

                  $ cat file2.txt
                  10.45 20 30
                  50.45 60 70





                  share|improve this answer


























                    9












                    9








                    9







                    Let's break this down. awk '{foo}' file will apply the expression foo to each line of file and print the result to the terminal (standard output). awk splits its input lines on white space (by default) and saves each field as $1, $2 etc.



                    So, the actual expression you are running means: read each input line, add 0.45 to the value of the first field and then print that field as well as the second and third one. This is most easily explained with a simple example:



                    $ cat file.txt 
                    10 20 30 40
                    50 60 70 80

                    $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt
                    10.45 20 30
                    50.45 60 70


                    So, as you can see, the awk script added 0.45 to the first field of each line and then printed it along with the second and third. The fourth was ignored since you did not tell it to print $4.



                    The next bit has nothing to do with awk, the > symbol is for output redirection and is used by the shell (bash or zsh or whatever you are using). In general command > file will save the output of command in the file file overwriting the contents of the file if it exists and creating it if it does not.



                    Putting everything together:



                    $ ls
                    file.txt

                    $ cat file.txt
                    10 20 30 40
                    50 60 70 80

                    $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt > file2.txt

                    $ ls
                    file2.txt file.txt

                    $ cat file2.txt
                    10.45 20 30
                    50.45 60 70





                    share|improve this answer













                    Let's break this down. awk '{foo}' file will apply the expression foo to each line of file and print the result to the terminal (standard output). awk splits its input lines on white space (by default) and saves each field as $1, $2 etc.



                    So, the actual expression you are running means: read each input line, add 0.45 to the value of the first field and then print that field as well as the second and third one. This is most easily explained with a simple example:



                    $ cat file.txt 
                    10 20 30 40
                    50 60 70 80

                    $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt
                    10.45 20 30
                    50.45 60 70


                    So, as you can see, the awk script added 0.45 to the first field of each line and then printed it along with the second and third. The fourth was ignored since you did not tell it to print $4.



                    The next bit has nothing to do with awk, the > symbol is for output redirection and is used by the shell (bash or zsh or whatever you are using). In general command > file will save the output of command in the file file overwriting the contents of the file if it exists and creating it if it does not.



                    Putting everything together:



                    $ ls
                    file.txt

                    $ cat file.txt
                    10 20 30 40
                    50 60 70 80

                    $ awk '{print $1+0.45 " " $2 " " $3 }' file.txt > file2.txt

                    $ ls
                    file2.txt file.txt

                    $ cat file2.txt
                    10.45 20 30
                    50.45 60 70






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 29 '14 at 21:58









                    terdonterdon

                    131k32258436




                    131k32258436

























                        1














                        file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.



                        awk reads each line of file1 and runs the script between {}



                        The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...



                        The parameters are printed except $1 is added with 0.45






                        share|improve this answer






























                          1














                          file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.



                          awk reads each line of file1 and runs the script between {}



                          The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...



                          The parameters are printed except $1 is added with 0.45






                          share|improve this answer




























                            1












                            1








                            1







                            file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.



                            awk reads each line of file1 and runs the script between {}



                            The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...



                            The parameters are printed except $1 is added with 0.45






                            share|improve this answer















                            file2 has 0.45 added to each value of first column (the x'es), column 2 and 3 are copied as is, anything else on the line is ignored.



                            awk reads each line of file1 and runs the script between {}



                            The script is run on every line, white spaced delimitered fields are assigned to positional parameters $1, $2 $3, ...



                            The parameters are printed except $1 is added with 0.45







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jan 29 '14 at 22:05

























                            answered Jan 29 '14 at 21:58









                            X TianX Tian

                            7,72712136




                            7,72712136























                                0














                                $1, $2, $3 mean placeholders of value got at the previous operation.






                                share|improve this answer








                                New contributor




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

























                                  0














                                  $1, $2, $3 mean placeholders of value got at the previous operation.






                                  share|improve this answer








                                  New contributor




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























                                    0












                                    0








                                    0







                                    $1, $2, $3 mean placeholders of value got at the previous operation.






                                    share|improve this answer








                                    New contributor




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










                                    $1, $2, $3 mean placeholders of value got at the previous operation.







                                    share|improve this answer








                                    New contributor




                                    imissyou 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 answer



                                    share|improve this answer






                                    New contributor




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









                                    answered 33 mins ago









                                    imissyouimissyou

                                    1




                                    1




                                    New contributor




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





                                    New contributor





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






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






























                                        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.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f111542%2fwhat-is-awk-print-10-45-2-3-file1-file2%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

                                        Accessing regular linux commands in Huawei's Dopra Linux

                                        Can't connect RFCOMM socket: Host is down

                                        Kernel panic - not syncing: Fatal Exception in Interrupt