Cutting numbers into a specific decimalsHow do I fetch only numbers in grep?How to calculate Pi decimals from a given offset?Is there a command to round decimal numbers in txt files?How to set default scale for bc calculator?How to grep two numbers from the same line at different places using bash?Separating even and odd numbersSED copy specific section to different filesCutting a string using sed

How to prevent a hosting company from accessing a VM's encryption keys?

How did medieval manors handle population growth? Were there room for more fields to be ploughed?

Are sweatpants frowned upon on flights?

What checks exist against overuse of presidential pardons in the USA?

Get contents before a colon

Is it unusual for a math department not to have a mail/web server?

If the UK Gov. has authority to cancel article 50 notification, why do they have to agree an extension with the EU

How to say "I only speak one language which is English" in French?

Printing a list as "a, b, c." using Python

Looking for a plural noun related to ‘fulcrum’ or ‘pivot’ that denotes multiple things as crucial to success

Should I judge the efficacy of Samadhi based on the ethical qualities of the meditator?

Why can't I identify major and minor chords?

Can I lend a small amount of my own money to a bank at the federal funds rate?

Why is there no Disney logo in MCU movies?

Journal published a paper, ignoring my objections as a referee

SQL Server - How to achieve READCOMMITED and NOLOCK at the same time?

web scraping images

Are there any to-scale diagrams of the TRAPPIST-1 system?

How does attacking during a conversation affect initiative?

Normalized Malbolge to Malbolge translator

Notice period 60 days but I need to join in 45 days

Is Nikon D500 a good fit for nature and ambient-lighting portraits and occasional other uses?

Why does this London Underground poster from 1924 have a Star of David atop a Christmas tree?

Count the number of triangles



Cutting numbers into a specific decimals


How do I fetch only numbers in grep?How to calculate Pi decimals from a given offset?Is there a command to round decimal numbers in txt files?How to set default scale for bc calculator?How to grep two numbers from the same line at different places using bash?Separating even and odd numbersSED copy specific section to different filesCutting a string using sed






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to cut all numbers in a file to the fifth decimal only. For example, I have this file:



1.0
12.2348604202 0.0000000000 0.0000000000
0.0000000000 3.0320000648 0.0000000000
-1.3752052829 0.0000000000 5.6183021388
Ga O
8 12
Direct
0.590021042 0.500000000 0.794251030
0.409978979 0.500000000 0.205748985
0.909978943 0.000000000 0.205749006
0.090021023 -0.000000000 0.794251030
0.658887031 0.000000000 0.314083014


So, I want to have the same file but with numbers with 5 decimal places only.










share|improve this question
































    2















    I want to cut all numbers in a file to the fifth decimal only. For example, I have this file:



    1.0
    12.2348604202 0.0000000000 0.0000000000
    0.0000000000 3.0320000648 0.0000000000
    -1.3752052829 0.0000000000 5.6183021388
    Ga O
    8 12
    Direct
    0.590021042 0.500000000 0.794251030
    0.409978979 0.500000000 0.205748985
    0.909978943 0.000000000 0.205749006
    0.090021023 -0.000000000 0.794251030
    0.658887031 0.000000000 0.314083014


    So, I want to have the same file but with numbers with 5 decimal places only.










    share|improve this question




























      2












      2








      2








      I want to cut all numbers in a file to the fifth decimal only. For example, I have this file:



      1.0
      12.2348604202 0.0000000000 0.0000000000
      0.0000000000 3.0320000648 0.0000000000
      -1.3752052829 0.0000000000 5.6183021388
      Ga O
      8 12
      Direct
      0.590021042 0.500000000 0.794251030
      0.409978979 0.500000000 0.205748985
      0.909978943 0.000000000 0.205749006
      0.090021023 -0.000000000 0.794251030
      0.658887031 0.000000000 0.314083014


      So, I want to have the same file but with numbers with 5 decimal places only.










      share|improve this question
















      I want to cut all numbers in a file to the fifth decimal only. For example, I have this file:



      1.0
      12.2348604202 0.0000000000 0.0000000000
      0.0000000000 3.0320000648 0.0000000000
      -1.3752052829 0.0000000000 5.6183021388
      Ga O
      8 12
      Direct
      0.590021042 0.500000000 0.794251030
      0.409978979 0.500000000 0.205748985
      0.909978943 0.000000000 0.205749006
      0.090021023 -0.000000000 0.794251030
      0.658887031 0.000000000 0.314083014


      So, I want to have the same file but with numbers with 5 decimal places only.







      command-line






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 3 hours ago









      dessert

      28.8k7 gold badges86 silver badges119 bronze badges




      28.8k7 gold badges86 silver badges119 bronze badges










      asked 9 hours ago









      Eslam SaadEslam Saad

      183 bronze badges




      183 bronze badges























          4 Answers
          4






          active

          oldest

          votes


















          3















          You can use sed:



          sed -E 's/([0-9]+.[0-9]5)[0-9]*/1/g' file


          Add -i option to add file in place.






          share|improve this answer


































            2















            With GNU awk:



            awk 'print gensub(/([0-9]+.[0-9]5)[0-9]*/, "\1", "g")' input_file > output_file


            This uses the awk function gensub to select a decimal number (/([0-9]+.[0-9]5)[0-9]*/) from a given file (input_file) and split it into two parts. The first part has 5 decimal places (([0-9]+.[0-9]5)) and the second part is the rest of the decimal number (([0-9]*)). gensub then replaces the selected number with its first part ("\1") and does that for all the decimal numbers it can find ("g") in input_file.



            The command then saves the result to an output file (> output_file).






            share|improve this answer


































              2















              With GNU sed:



              sed -E 's/.([0-9]5)[0-9]*/.1/g' file


              Output:



              1.0
              12.23486 0.00000 0.00000
              0.00000 3.03200 0.00000
              -1.37520 0.00000 5.61830
              Ga O
              8 12
              Direct
              0.59002 0.50000 0.79425
              0.40997 0.50000 0.20574
              0.90997 0.00000 0.20574
              0.09002 -0.00000 0.79425
              0.65888 0.00000 0.31408



              Use extended regular expressions with -E:



              sed -E




              Match the pattern .<five digits><n digits> with .([0-9]5)[0-9]*. Capture the 5 digits following the dot . with ([0-9]5)



              s/.([0-9]5)[0-9]*/



              Replace the match with the dot . and the captured pattern:



              /.1/






              share|improve this answer



























              • Could you add an explanation and maybe an example output please?

                – dessert
                3 hours ago











              • @dessert done it.

                – guillermo chamorro
                2 hours ago


















              0















              If you don't mind the integers also being converted to floating point, you could use numfmt:



              $ numfmt --field=1- --format=%.5f --invalid=ignore < file
              1.00000
              12.23487 0.00000 0.00000
              0.00000 3.03201 0.00000
              -1.37521 0.00000 5.61831
              Ga O
              8.00000 12.00000
              Direct
              0.59003 0.50000 0.79426
              0.40998 0.50000 0.20575
              0.90998 0.00000 0.20575
              0.09003 0.00000 0.79426
              0.65889 0.00000 0.31409





              share|improve this answer



























                Your Answer








                StackExchange.ready(function()
                var channelOptions =
                tags: "".split(" "),
                id: "89"
                ;
                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: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                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%2faskubuntu.com%2fquestions%2f1169138%2fcutting-numbers-into-a-specific-decimals%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                3















                You can use sed:



                sed -E 's/([0-9]+.[0-9]5)[0-9]*/1/g' file


                Add -i option to add file in place.






                share|improve this answer































                  3















                  You can use sed:



                  sed -E 's/([0-9]+.[0-9]5)[0-9]*/1/g' file


                  Add -i option to add file in place.






                  share|improve this answer





























                    3














                    3










                    3









                    You can use sed:



                    sed -E 's/([0-9]+.[0-9]5)[0-9]*/1/g' file


                    Add -i option to add file in place.






                    share|improve this answer















                    You can use sed:



                    sed -E 's/([0-9]+.[0-9]5)[0-9]*/1/g' file


                    Add -i option to add file in place.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 8 hours ago

























                    answered 9 hours ago









                    pLumopLumo

                    10.8k23 silver badges51 bronze badges




                    10.8k23 silver badges51 bronze badges


























                        2















                        With GNU awk:



                        awk 'print gensub(/([0-9]+.[0-9]5)[0-9]*/, "\1", "g")' input_file > output_file


                        This uses the awk function gensub to select a decimal number (/([0-9]+.[0-9]5)[0-9]*/) from a given file (input_file) and split it into two parts. The first part has 5 decimal places (([0-9]+.[0-9]5)) and the second part is the rest of the decimal number (([0-9]*)). gensub then replaces the selected number with its first part ("\1") and does that for all the decimal numbers it can find ("g") in input_file.



                        The command then saves the result to an output file (> output_file).






                        share|improve this answer































                          2















                          With GNU awk:



                          awk 'print gensub(/([0-9]+.[0-9]5)[0-9]*/, "\1", "g")' input_file > output_file


                          This uses the awk function gensub to select a decimal number (/([0-9]+.[0-9]5)[0-9]*/) from a given file (input_file) and split it into two parts. The first part has 5 decimal places (([0-9]+.[0-9]5)) and the second part is the rest of the decimal number (([0-9]*)). gensub then replaces the selected number with its first part ("\1") and does that for all the decimal numbers it can find ("g") in input_file.



                          The command then saves the result to an output file (> output_file).






                          share|improve this answer





























                            2














                            2










                            2









                            With GNU awk:



                            awk 'print gensub(/([0-9]+.[0-9]5)[0-9]*/, "\1", "g")' input_file > output_file


                            This uses the awk function gensub to select a decimal number (/([0-9]+.[0-9]5)[0-9]*/) from a given file (input_file) and split it into two parts. The first part has 5 decimal places (([0-9]+.[0-9]5)) and the second part is the rest of the decimal number (([0-9]*)). gensub then replaces the selected number with its first part ("\1") and does that for all the decimal numbers it can find ("g") in input_file.



                            The command then saves the result to an output file (> output_file).






                            share|improve this answer















                            With GNU awk:



                            awk 'print gensub(/([0-9]+.[0-9]5)[0-9]*/, "\1", "g")' input_file > output_file


                            This uses the awk function gensub to select a decimal number (/([0-9]+.[0-9]5)[0-9]*/) from a given file (input_file) and split it into two parts. The first part has 5 decimal places (([0-9]+.[0-9]5)) and the second part is the rest of the decimal number (([0-9]*)). gensub then replaces the selected number with its first part ("\1") and does that for all the decimal numbers it can find ("g") in input_file.



                            The command then saves the result to an output file (> output_file).







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 3 hours ago

























                            answered 7 hours ago









                            user3140225user3140225

                            1,2867 silver badges19 bronze badges




                            1,2867 silver badges19 bronze badges
























                                2















                                With GNU sed:



                                sed -E 's/.([0-9]5)[0-9]*/.1/g' file


                                Output:



                                1.0
                                12.23486 0.00000 0.00000
                                0.00000 3.03200 0.00000
                                -1.37520 0.00000 5.61830
                                Ga O
                                8 12
                                Direct
                                0.59002 0.50000 0.79425
                                0.40997 0.50000 0.20574
                                0.90997 0.00000 0.20574
                                0.09002 -0.00000 0.79425
                                0.65888 0.00000 0.31408



                                Use extended regular expressions with -E:



                                sed -E




                                Match the pattern .<five digits><n digits> with .([0-9]5)[0-9]*. Capture the 5 digits following the dot . with ([0-9]5)



                                s/.([0-9]5)[0-9]*/



                                Replace the match with the dot . and the captured pattern:



                                /.1/






                                share|improve this answer



























                                • Could you add an explanation and maybe an example output please?

                                  – dessert
                                  3 hours ago











                                • @dessert done it.

                                  – guillermo chamorro
                                  2 hours ago















                                2















                                With GNU sed:



                                sed -E 's/.([0-9]5)[0-9]*/.1/g' file


                                Output:



                                1.0
                                12.23486 0.00000 0.00000
                                0.00000 3.03200 0.00000
                                -1.37520 0.00000 5.61830
                                Ga O
                                8 12
                                Direct
                                0.59002 0.50000 0.79425
                                0.40997 0.50000 0.20574
                                0.90997 0.00000 0.20574
                                0.09002 -0.00000 0.79425
                                0.65888 0.00000 0.31408



                                Use extended regular expressions with -E:



                                sed -E




                                Match the pattern .<five digits><n digits> with .([0-9]5)[0-9]*. Capture the 5 digits following the dot . with ([0-9]5)



                                s/.([0-9]5)[0-9]*/



                                Replace the match with the dot . and the captured pattern:



                                /.1/






                                share|improve this answer



























                                • Could you add an explanation and maybe an example output please?

                                  – dessert
                                  3 hours ago











                                • @dessert done it.

                                  – guillermo chamorro
                                  2 hours ago













                                2














                                2










                                2









                                With GNU sed:



                                sed -E 's/.([0-9]5)[0-9]*/.1/g' file


                                Output:



                                1.0
                                12.23486 0.00000 0.00000
                                0.00000 3.03200 0.00000
                                -1.37520 0.00000 5.61830
                                Ga O
                                8 12
                                Direct
                                0.59002 0.50000 0.79425
                                0.40997 0.50000 0.20574
                                0.90997 0.00000 0.20574
                                0.09002 -0.00000 0.79425
                                0.65888 0.00000 0.31408



                                Use extended regular expressions with -E:



                                sed -E




                                Match the pattern .<five digits><n digits> with .([0-9]5)[0-9]*. Capture the 5 digits following the dot . with ([0-9]5)



                                s/.([0-9]5)[0-9]*/



                                Replace the match with the dot . and the captured pattern:



                                /.1/






                                share|improve this answer















                                With GNU sed:



                                sed -E 's/.([0-9]5)[0-9]*/.1/g' file


                                Output:



                                1.0
                                12.23486 0.00000 0.00000
                                0.00000 3.03200 0.00000
                                -1.37520 0.00000 5.61830
                                Ga O
                                8 12
                                Direct
                                0.59002 0.50000 0.79425
                                0.40997 0.50000 0.20574
                                0.90997 0.00000 0.20574
                                0.09002 -0.00000 0.79425
                                0.65888 0.00000 0.31408



                                Use extended regular expressions with -E:



                                sed -E




                                Match the pattern .<five digits><n digits> with .([0-9]5)[0-9]*. Capture the 5 digits following the dot . with ([0-9]5)



                                s/.([0-9]5)[0-9]*/



                                Replace the match with the dot . and the captured pattern:



                                /.1/







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited 2 hours ago

























                                answered 9 hours ago









                                guillermo chamorroguillermo chamorro

                                5821 silver badge12 bronze badges




                                5821 silver badge12 bronze badges















                                • Could you add an explanation and maybe an example output please?

                                  – dessert
                                  3 hours ago











                                • @dessert done it.

                                  – guillermo chamorro
                                  2 hours ago

















                                • Could you add an explanation and maybe an example output please?

                                  – dessert
                                  3 hours ago











                                • @dessert done it.

                                  – guillermo chamorro
                                  2 hours ago
















                                Could you add an explanation and maybe an example output please?

                                – dessert
                                3 hours ago





                                Could you add an explanation and maybe an example output please?

                                – dessert
                                3 hours ago













                                @dessert done it.

                                – guillermo chamorro
                                2 hours ago





                                @dessert done it.

                                – guillermo chamorro
                                2 hours ago











                                0















                                If you don't mind the integers also being converted to floating point, you could use numfmt:



                                $ numfmt --field=1- --format=%.5f --invalid=ignore < file
                                1.00000
                                12.23487 0.00000 0.00000
                                0.00000 3.03201 0.00000
                                -1.37521 0.00000 5.61831
                                Ga O
                                8.00000 12.00000
                                Direct
                                0.59003 0.50000 0.79426
                                0.40998 0.50000 0.20575
                                0.90998 0.00000 0.20575
                                0.09003 0.00000 0.79426
                                0.65889 0.00000 0.31409





                                share|improve this answer





























                                  0















                                  If you don't mind the integers also being converted to floating point, you could use numfmt:



                                  $ numfmt --field=1- --format=%.5f --invalid=ignore < file
                                  1.00000
                                  12.23487 0.00000 0.00000
                                  0.00000 3.03201 0.00000
                                  -1.37521 0.00000 5.61831
                                  Ga O
                                  8.00000 12.00000
                                  Direct
                                  0.59003 0.50000 0.79426
                                  0.40998 0.50000 0.20575
                                  0.90998 0.00000 0.20575
                                  0.09003 0.00000 0.79426
                                  0.65889 0.00000 0.31409





                                  share|improve this answer



























                                    0














                                    0










                                    0









                                    If you don't mind the integers also being converted to floating point, you could use numfmt:



                                    $ numfmt --field=1- --format=%.5f --invalid=ignore < file
                                    1.00000
                                    12.23487 0.00000 0.00000
                                    0.00000 3.03201 0.00000
                                    -1.37521 0.00000 5.61831
                                    Ga O
                                    8.00000 12.00000
                                    Direct
                                    0.59003 0.50000 0.79426
                                    0.40998 0.50000 0.20575
                                    0.90998 0.00000 0.20575
                                    0.09003 0.00000 0.79426
                                    0.65889 0.00000 0.31409





                                    share|improve this answer













                                    If you don't mind the integers also being converted to floating point, you could use numfmt:



                                    $ numfmt --field=1- --format=%.5f --invalid=ignore < file
                                    1.00000
                                    12.23487 0.00000 0.00000
                                    0.00000 3.03201 0.00000
                                    -1.37521 0.00000 5.61831
                                    Ga O
                                    8.00000 12.00000
                                    Direct
                                    0.59003 0.50000 0.79426
                                    0.40998 0.50000 0.20575
                                    0.90998 0.00000 0.20575
                                    0.09003 0.00000 0.79426
                                    0.65889 0.00000 0.31409






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 19 mins ago









                                    steeldriversteeldriver

                                    78.2k12 gold badges129 silver badges210 bronze badges




                                    78.2k12 gold badges129 silver badges210 bronze badges






























                                        draft saved

                                        draft discarded
















































                                        Thanks for contributing an answer to Ask Ubuntu!


                                        • 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%2faskubuntu.com%2fquestions%2f1169138%2fcutting-numbers-into-a-specific-decimals%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

                                        Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                        Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                        199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單