Manipulate scientific format without the “e”How to adjust numeric fields in a text fileHow to calculate...

How to deny access to SQL Server to certain login over SSMS, but allow over .Net SqlClient Data Provider

Magento 2: Override XML file from vendor folder to app folder doesn't work/update

Second-rate spelling

Why do members of Congress in committee hearings ask witnesses the same question multiple times?

Contradiction with Banach Fixed Point Theorem

Must a tritone substitution use a dominant seventh chord?

How do I construct an nxn matrix?

I can't die. Who am I?

Borrowing Characters

Did 5.25" floppies undergo a change in magnetic coating?

Non-Italian European mafias in USA?

What is better: yes / no radio, or simple checkbox?

Compare four integers, return word based on maximum

Replacement ford fiesta radiator has extra hose

Hacker Rank: Array left rotation

Where was Karl Mordo in Infinity War?

It took me a lot of time to make this, pls like. (YouTube Comments #1)

Skis versus snow shoes - when to choose which for travelling the backcountry?

Can you use a beast's innate abilities while polymorphed?

Does music exist in Panem? And if so, what kinds of music?

When was drinking water recognized as crucial in marathon running?

Is there any relevance to Thor getting his hair cut other than comedic value?

Where is this triangular-shaped space station from?

Avoiding unpacking an array when altering its dimension



Manipulate scientific format without the “e”


How to adjust numeric fields in a text fileHow to calculate (weighted) majority over columns?Parse/Manipulate in awkhow can I add an extra character after a word searchAdd a number in a huge ASCII fileBash to join columns from multiple filesSelect the lines with exactly two columns in LinuxUsing AWK to calculate mean and variance of columnsIf column matches another file, print every line with match (awk/grep)count how many times each number occurs













2















I am trying to manipulate a file which contains numbers in scientific notation, but without the e symbol, i.e. 1.2e+3 is written as 1.2+3.



The easiest thing I thought to doing with awk was to replace + with e+, using the gsub function and do my calculation in the new file. The same goes for the minus case. So a simple fix could be done using the following command



awk '{gsub("+", "e+", $1); print $1, $2, $3, $4, $5}' file_in


and do the same in all the columns.



However the file contains also negative numbers which makes thing a bit complicated. A sample file can be seen bellow



 1.056000+0 5.000000-1 2.454400-3 2.914800-2 8.141500-6
2.043430+1 5.000000-1 2.750500-3 2.698100-2-2.034300-4
3.829842+1 5.000000-1 1.969923-2 2.211364-2 9.499900-6
4.168521+1 5.000000-1 1.601262-2 3.030919-2-3.372000-6
6.661784+1 5.000000-1 5.250575-2 3.443669-2 2.585500-5
7.278104+1 5.000000-1 2.137055-2 2.601701-2 8.999800-5
9.077287+1 5.000000-1 1.320498-2 2.961020-2-1.011600-5
9.248130+1 5.000000-1 3.069610-3 2.786329-2-6.317000-5
1.049935+2 5.000000-1 4.218794-2 3.321955-2-5.097000-6
1.216283+2 5.000000-1 1.432105-2 3.077165-2 4.300300-5


Any idea on how to manipulate and calculations with such a file?










share|improve this question

























  • How do you want to make calculations with a format like that 2.698100e-2-2.034300e-4 ?

    – ctac_
    48 mins ago
















2















I am trying to manipulate a file which contains numbers in scientific notation, but without the e symbol, i.e. 1.2e+3 is written as 1.2+3.



The easiest thing I thought to doing with awk was to replace + with e+, using the gsub function and do my calculation in the new file. The same goes for the minus case. So a simple fix could be done using the following command



awk '{gsub("+", "e+", $1); print $1, $2, $3, $4, $5}' file_in


and do the same in all the columns.



However the file contains also negative numbers which makes thing a bit complicated. A sample file can be seen bellow



 1.056000+0 5.000000-1 2.454400-3 2.914800-2 8.141500-6
2.043430+1 5.000000-1 2.750500-3 2.698100-2-2.034300-4
3.829842+1 5.000000-1 1.969923-2 2.211364-2 9.499900-6
4.168521+1 5.000000-1 1.601262-2 3.030919-2-3.372000-6
6.661784+1 5.000000-1 5.250575-2 3.443669-2 2.585500-5
7.278104+1 5.000000-1 2.137055-2 2.601701-2 8.999800-5
9.077287+1 5.000000-1 1.320498-2 2.961020-2-1.011600-5
9.248130+1 5.000000-1 3.069610-3 2.786329-2-6.317000-5
1.049935+2 5.000000-1 4.218794-2 3.321955-2-5.097000-6
1.216283+2 5.000000-1 1.432105-2 3.077165-2 4.300300-5


Any idea on how to manipulate and calculations with such a file?










share|improve this question

























  • How do you want to make calculations with a format like that 2.698100e-2-2.034300e-4 ?

    – ctac_
    48 mins ago














2












2








2








I am trying to manipulate a file which contains numbers in scientific notation, but without the e symbol, i.e. 1.2e+3 is written as 1.2+3.



The easiest thing I thought to doing with awk was to replace + with e+, using the gsub function and do my calculation in the new file. The same goes for the minus case. So a simple fix could be done using the following command



awk '{gsub("+", "e+", $1); print $1, $2, $3, $4, $5}' file_in


and do the same in all the columns.



However the file contains also negative numbers which makes thing a bit complicated. A sample file can be seen bellow



 1.056000+0 5.000000-1 2.454400-3 2.914800-2 8.141500-6
2.043430+1 5.000000-1 2.750500-3 2.698100-2-2.034300-4
3.829842+1 5.000000-1 1.969923-2 2.211364-2 9.499900-6
4.168521+1 5.000000-1 1.601262-2 3.030919-2-3.372000-6
6.661784+1 5.000000-1 5.250575-2 3.443669-2 2.585500-5
7.278104+1 5.000000-1 2.137055-2 2.601701-2 8.999800-5
9.077287+1 5.000000-1 1.320498-2 2.961020-2-1.011600-5
9.248130+1 5.000000-1 3.069610-3 2.786329-2-6.317000-5
1.049935+2 5.000000-1 4.218794-2 3.321955-2-5.097000-6
1.216283+2 5.000000-1 1.432105-2 3.077165-2 4.300300-5


Any idea on how to manipulate and calculations with such a file?










share|improve this question
















I am trying to manipulate a file which contains numbers in scientific notation, but without the e symbol, i.e. 1.2e+3 is written as 1.2+3.



The easiest thing I thought to doing with awk was to replace + with e+, using the gsub function and do my calculation in the new file. The same goes for the minus case. So a simple fix could be done using the following command



awk '{gsub("+", "e+", $1); print $1, $2, $3, $4, $5}' file_in


and do the same in all the columns.



However the file contains also negative numbers which makes thing a bit complicated. A sample file can be seen bellow



 1.056000+0 5.000000-1 2.454400-3 2.914800-2 8.141500-6
2.043430+1 5.000000-1 2.750500-3 2.698100-2-2.034300-4
3.829842+1 5.000000-1 1.969923-2 2.211364-2 9.499900-6
4.168521+1 5.000000-1 1.601262-2 3.030919-2-3.372000-6
6.661784+1 5.000000-1 5.250575-2 3.443669-2 2.585500-5
7.278104+1 5.000000-1 2.137055-2 2.601701-2 8.999800-5
9.077287+1 5.000000-1 1.320498-2 2.961020-2-1.011600-5
9.248130+1 5.000000-1 3.069610-3 2.786329-2-6.317000-5
1.049935+2 5.000000-1 4.218794-2 3.321955-2-5.097000-6
1.216283+2 5.000000-1 1.432105-2 3.077165-2 4.300300-5


Any idea on how to manipulate and calculations with such a file?







text-processing awk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Tomasz

10k52966




10k52966










asked 2 hours ago









ThanosThanos

187111




187111













  • How do you want to make calculations with a format like that 2.698100e-2-2.034300e-4 ?

    – ctac_
    48 mins ago



















  • How do you want to make calculations with a format like that 2.698100e-2-2.034300e-4 ?

    – ctac_
    48 mins ago

















How do you want to make calculations with a format like that 2.698100e-2-2.034300e-4 ?

– ctac_
48 mins ago





How do you want to make calculations with a format like that 2.698100e-2-2.034300e-4 ?

– ctac_
48 mins ago










2 Answers
2






active

oldest

votes


















3














Is this output correct?



 1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6
2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2-2.034300e-4
3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2-3.372000e-6
6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2-1.011600e-5
9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2-6.317000e-5
1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2-5.097000e-6
1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5


Code:



perl -lne 's/(.d+)(+|-)/1e2/g; print' sample


Explanation:




  • -lne take care of line endings, process each input line, execute the code that follows



  • s/(.d+)(+|-)/1e2/g:




    • substitute (s)


    • (.d+)(+|-) find two groups of (a dot and numbers) and (a plus or minus)


    • 1e2 substitute them with the first group then e then the second group


    • g globally - don't stop at the first substitution in each line, but process all possible hits



  • print print the line



  • sample input file


This one adds space if it's missing. In fact it puts space between the numbers regardless. Ie. if there were two spaces in some case, there would be only one in the output.



perl -lne 's/(.d+)(+|-)(d+)(s*)/1e23 /g; print' sample


Most of it is similar to the previous one. The new thing is the (d+) group nr 3 and the (s*) group nr 4. * here means optional. In the substitution no 4 is used. There's a space instead.



The output is this:



 1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6 
2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2 -2.034300e-4
3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2 -3.372000e-6
6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2 -1.011600e-5
9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2 -6.317000e-5
1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2 -5.097000e-6
1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5





share|improve this answer


























  • Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

    – Thanos
    2 hours ago











  • Is it also possible to separate the last column ($5$) from the previous one with a space?

    – Thanos
    1 hour ago











  • You are perfect! Thank you very much for your help!

    – Thanos
    1 hour ago











  • @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

    – Tomasz
    1 hour ago













  • Thank you very much for the help!!!

    – Thanos
    1 hour ago



















0














You could also use sed, e.g.:



<infile sed -E 's/([0-9])([+-])([0-9])/1e23/g' | awk '{ print $1 + 0 }'


Output:



1.056
20.4343
38.2984
41.6852
66.6178
72.781
90.7729
92.4813
104.993
121.628





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%2f504412%2fmanipulate-scientific-format-without-the-e%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Is this output correct?



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2-2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2-3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2-1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2-6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2-5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5


    Code:



    perl -lne 's/(.d+)(+|-)/1e2/g; print' sample


    Explanation:




    • -lne take care of line endings, process each input line, execute the code that follows



    • s/(.d+)(+|-)/1e2/g:




      • substitute (s)


      • (.d+)(+|-) find two groups of (a dot and numbers) and (a plus or minus)


      • 1e2 substitute them with the first group then e then the second group


      • g globally - don't stop at the first substitution in each line, but process all possible hits



    • print print the line



    • sample input file


    This one adds space if it's missing. In fact it puts space between the numbers regardless. Ie. if there were two spaces in some case, there would be only one in the output.



    perl -lne 's/(.d+)(+|-)(d+)(s*)/1e23 /g; print' sample


    Most of it is similar to the previous one. The new thing is the (d+) group nr 3 and the (s*) group nr 4. * here means optional. In the substitution no 4 is used. There's a space instead.



    The output is this:



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6 
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2 -2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2 -3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2 -1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2 -6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2 -5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5





    share|improve this answer


























    • Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

      – Thanos
      2 hours ago











    • Is it also possible to separate the last column ($5$) from the previous one with a space?

      – Thanos
      1 hour ago











    • You are perfect! Thank you very much for your help!

      – Thanos
      1 hour ago











    • @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

      – Tomasz
      1 hour ago













    • Thank you very much for the help!!!

      – Thanos
      1 hour ago
















    3














    Is this output correct?



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2-2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2-3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2-1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2-6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2-5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5


    Code:



    perl -lne 's/(.d+)(+|-)/1e2/g; print' sample


    Explanation:




    • -lne take care of line endings, process each input line, execute the code that follows



    • s/(.d+)(+|-)/1e2/g:




      • substitute (s)


      • (.d+)(+|-) find two groups of (a dot and numbers) and (a plus or minus)


      • 1e2 substitute them with the first group then e then the second group


      • g globally - don't stop at the first substitution in each line, but process all possible hits



    • print print the line



    • sample input file


    This one adds space if it's missing. In fact it puts space between the numbers regardless. Ie. if there were two spaces in some case, there would be only one in the output.



    perl -lne 's/(.d+)(+|-)(d+)(s*)/1e23 /g; print' sample


    Most of it is similar to the previous one. The new thing is the (d+) group nr 3 and the (s*) group nr 4. * here means optional. In the substitution no 4 is used. There's a space instead.



    The output is this:



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6 
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2 -2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2 -3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2 -1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2 -6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2 -5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5





    share|improve this answer


























    • Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

      – Thanos
      2 hours ago











    • Is it also possible to separate the last column ($5$) from the previous one with a space?

      – Thanos
      1 hour ago











    • You are perfect! Thank you very much for your help!

      – Thanos
      1 hour ago











    • @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

      – Tomasz
      1 hour ago













    • Thank you very much for the help!!!

      – Thanos
      1 hour ago














    3












    3








    3







    Is this output correct?



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2-2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2-3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2-1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2-6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2-5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5


    Code:



    perl -lne 's/(.d+)(+|-)/1e2/g; print' sample


    Explanation:




    • -lne take care of line endings, process each input line, execute the code that follows



    • s/(.d+)(+|-)/1e2/g:




      • substitute (s)


      • (.d+)(+|-) find two groups of (a dot and numbers) and (a plus or minus)


      • 1e2 substitute them with the first group then e then the second group


      • g globally - don't stop at the first substitution in each line, but process all possible hits



    • print print the line



    • sample input file


    This one adds space if it's missing. In fact it puts space between the numbers regardless. Ie. if there were two spaces in some case, there would be only one in the output.



    perl -lne 's/(.d+)(+|-)(d+)(s*)/1e23 /g; print' sample


    Most of it is similar to the previous one. The new thing is the (d+) group nr 3 and the (s*) group nr 4. * here means optional. In the substitution no 4 is used. There's a space instead.



    The output is this:



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6 
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2 -2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2 -3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2 -1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2 -6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2 -5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5





    share|improve this answer















    Is this output correct?



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2-2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2-3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2-1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2-6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2-5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5


    Code:



    perl -lne 's/(.d+)(+|-)/1e2/g; print' sample


    Explanation:




    • -lne take care of line endings, process each input line, execute the code that follows



    • s/(.d+)(+|-)/1e2/g:




      • substitute (s)


      • (.d+)(+|-) find two groups of (a dot and numbers) and (a plus or minus)


      • 1e2 substitute them with the first group then e then the second group


      • g globally - don't stop at the first substitution in each line, but process all possible hits



    • print print the line



    • sample input file


    This one adds space if it's missing. In fact it puts space between the numbers regardless. Ie. if there were two spaces in some case, there would be only one in the output.



    perl -lne 's/(.d+)(+|-)(d+)(s*)/1e23 /g; print' sample


    Most of it is similar to the previous one. The new thing is the (d+) group nr 3 and the (s*) group nr 4. * here means optional. In the substitution no 4 is used. There's a space instead.



    The output is this:



     1.056000e+0 5.000000e-1 2.454400e-3 2.914800e-2 8.141500e-6 
    2.043430e+1 5.000000e-1 2.750500e-3 2.698100e-2 -2.034300e-4
    3.829842e+1 5.000000e-1 1.969923e-2 2.211364e-2 9.499900e-6
    4.168521e+1 5.000000e-1 1.601262e-2 3.030919e-2 -3.372000e-6
    6.661784e+1 5.000000e-1 5.250575e-2 3.443669e-2 2.585500e-5
    7.278104e+1 5.000000e-1 2.137055e-2 2.601701e-2 8.999800e-5
    9.077287e+1 5.000000e-1 1.320498e-2 2.961020e-2 -1.011600e-5
    9.248130e+1 5.000000e-1 3.069610e-3 2.786329e-2 -6.317000e-5
    1.049935e+2 5.000000e-1 4.218794e-2 3.321955e-2 -5.097000e-6
    1.216283e+2 5.000000e-1 1.432105e-2 3.077165e-2 4.300300e-5






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 1 hour ago

























    answered 2 hours ago









    TomaszTomasz

    10k52966




    10k52966













    • Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

      – Thanos
      2 hours ago











    • Is it also possible to separate the last column ($5$) from the previous one with a space?

      – Thanos
      1 hour ago











    • You are perfect! Thank you very much for your help!

      – Thanos
      1 hour ago











    • @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

      – Tomasz
      1 hour ago













    • Thank you very much for the help!!!

      – Thanos
      1 hour ago



















    • Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

      – Thanos
      2 hours ago











    • Is it also possible to separate the last column ($5$) from the previous one with a space?

      – Thanos
      1 hour ago











    • You are perfect! Thank you very much for your help!

      – Thanos
      1 hour ago











    • @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

      – Tomasz
      1 hour ago













    • Thank you very much for the help!!!

      – Thanos
      1 hour ago

















    Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

    – Thanos
    2 hours ago





    Thank you very much for the answer! Yes it seems correct!! Can you explain what you did, for future reference?

    – Thanos
    2 hours ago













    Is it also possible to separate the last column ($5$) from the previous one with a space?

    – Thanos
    1 hour ago





    Is it also possible to separate the last column ($5$) from the previous one with a space?

    – Thanos
    1 hour ago













    You are perfect! Thank you very much for your help!

    – Thanos
    1 hour ago





    You are perfect! Thank you very much for your help!

    – Thanos
    1 hour ago













    @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

    – Tomasz
    1 hour ago







    @Thanos See the update. And notice I added a backslash before . in the first group. This is correct. Without this backslash the dot would not mean a literal dot.

    – Tomasz
    1 hour ago















    Thank you very much for the help!!!

    – Thanos
    1 hour ago





    Thank you very much for the help!!!

    – Thanos
    1 hour ago













    0














    You could also use sed, e.g.:



    <infile sed -E 's/([0-9])([+-])([0-9])/1e23/g' | awk '{ print $1 + 0 }'


    Output:



    1.056
    20.4343
    38.2984
    41.6852
    66.6178
    72.781
    90.7729
    92.4813
    104.993
    121.628





    share|improve this answer




























      0














      You could also use sed, e.g.:



      <infile sed -E 's/([0-9])([+-])([0-9])/1e23/g' | awk '{ print $1 + 0 }'


      Output:



      1.056
      20.4343
      38.2984
      41.6852
      66.6178
      72.781
      90.7729
      92.4813
      104.993
      121.628





      share|improve this answer


























        0












        0








        0







        You could also use sed, e.g.:



        <infile sed -E 's/([0-9])([+-])([0-9])/1e23/g' | awk '{ print $1 + 0 }'


        Output:



        1.056
        20.4343
        38.2984
        41.6852
        66.6178
        72.781
        90.7729
        92.4813
        104.993
        121.628





        share|improve this answer













        You could also use sed, e.g.:



        <infile sed -E 's/([0-9])([+-])([0-9])/1e23/g' | awk '{ print $1 + 0 }'


        Output:



        1.056
        20.4343
        38.2984
        41.6852
        66.6178
        72.781
        90.7729
        92.4813
        104.993
        121.628






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 32 mins ago









        ThorThor

        11.8k13459




        11.8k13459






























            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%2f504412%2fmanipulate-scientific-format-without-the-e%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

            As a Security Precaution, the user account has been locked The Next CEO of Stack OverflowMS...

            Список ссавців Італії Природоохоронні статуси | Список |...

            Українські прізвища Зміст Історичні відомості |...