How to have trailing zero in CSV

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





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







up vote
3
down vote

favorite












The following is the sample csv file:



12354506.0,4
13129229.0,4
815612,5
7624107.0,5
6056548.0,5


The trailing zero in the first column is formatted to hole number on CSV VIEWER.



Is there any option to have trailing zero?



I was able to have trailing zero by prefix single quotes to the first column. But it looks odd with single quotes.



'12354506.0,4
'13129229.0,4
'815612,5
'7624107.0,5
'6056548.0,5






share|improve this question





















  • This is likely a feature of your CSV viewer software (you don't mention what the software is). It may have the option to show a configurable number of decimal places for numeric data.
    – Kusalananda
    Jul 27 at 6:38











  • @Kusalananda Yes, we can configure the decimal places, but it create a conflict in 3rd row of my input file since it doesn't have decimal value.
    – abab kren
    Jul 27 at 6:51










  • Why is this tagged sendmail?
    – Rob
    Jul 27 at 11:25
















up vote
3
down vote

favorite












The following is the sample csv file:



12354506.0,4
13129229.0,4
815612,5
7624107.0,5
6056548.0,5


The trailing zero in the first column is formatted to hole number on CSV VIEWER.



Is there any option to have trailing zero?



I was able to have trailing zero by prefix single quotes to the first column. But it looks odd with single quotes.



'12354506.0,4
'13129229.0,4
'815612,5
'7624107.0,5
'6056548.0,5






share|improve this question





















  • This is likely a feature of your CSV viewer software (you don't mention what the software is). It may have the option to show a configurable number of decimal places for numeric data.
    – Kusalananda
    Jul 27 at 6:38











  • @Kusalananda Yes, we can configure the decimal places, but it create a conflict in 3rd row of my input file since it doesn't have decimal value.
    – abab kren
    Jul 27 at 6:51










  • Why is this tagged sendmail?
    – Rob
    Jul 27 at 11:25












up vote
3
down vote

favorite









up vote
3
down vote

favorite











The following is the sample csv file:



12354506.0,4
13129229.0,4
815612,5
7624107.0,5
6056548.0,5


The trailing zero in the first column is formatted to hole number on CSV VIEWER.



Is there any option to have trailing zero?



I was able to have trailing zero by prefix single quotes to the first column. But it looks odd with single quotes.



'12354506.0,4
'13129229.0,4
'815612,5
'7624107.0,5
'6056548.0,5






share|improve this question













The following is the sample csv file:



12354506.0,4
13129229.0,4
815612,5
7624107.0,5
6056548.0,5


The trailing zero in the first column is formatted to hole number on CSV VIEWER.



Is there any option to have trailing zero?



I was able to have trailing zero by prefix single quotes to the first column. But it looks odd with single quotes.



'12354506.0,4
'13129229.0,4
'815612,5
'7624107.0,5
'6056548.0,5








share|improve this question












share|improve this question




share|improve this question








edited Jul 27 at 6:34









SivaPrasath

3,46311535




3,46311535









asked Jul 27 at 6:18









abab kren

184




184











  • This is likely a feature of your CSV viewer software (you don't mention what the software is). It may have the option to show a configurable number of decimal places for numeric data.
    – Kusalananda
    Jul 27 at 6:38











  • @Kusalananda Yes, we can configure the decimal places, but it create a conflict in 3rd row of my input file since it doesn't have decimal value.
    – abab kren
    Jul 27 at 6:51










  • Why is this tagged sendmail?
    – Rob
    Jul 27 at 11:25
















  • This is likely a feature of your CSV viewer software (you don't mention what the software is). It may have the option to show a configurable number of decimal places for numeric data.
    – Kusalananda
    Jul 27 at 6:38











  • @Kusalananda Yes, we can configure the decimal places, but it create a conflict in 3rd row of my input file since it doesn't have decimal value.
    – abab kren
    Jul 27 at 6:51










  • Why is this tagged sendmail?
    – Rob
    Jul 27 at 11:25















This is likely a feature of your CSV viewer software (you don't mention what the software is). It may have the option to show a configurable number of decimal places for numeric data.
– Kusalananda
Jul 27 at 6:38





This is likely a feature of your CSV viewer software (you don't mention what the software is). It may have the option to show a configurable number of decimal places for numeric data.
– Kusalananda
Jul 27 at 6:38













@Kusalananda Yes, we can configure the decimal places, but it create a conflict in 3rd row of my input file since it doesn't have decimal value.
– abab kren
Jul 27 at 6:51




@Kusalananda Yes, we can configure the decimal places, but it create a conflict in 3rd row of my input file since it doesn't have decimal value.
– abab kren
Jul 27 at 6:51












Why is this tagged sendmail?
– Rob
Jul 27 at 11:25




Why is this tagged sendmail?
– Rob
Jul 27 at 11:25










3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










It's purely behavior of CVS viewer which you are using. I'm able to replicate the same issue with MS Excel.



awk -F "," 'print "=""$1"","$2' test.csv > test3.csv



  • = will force the data to be text.

To edit the file.



echo "$(awk -F "," 'print "=""$1"","$2' test.csv)" > test.csv





share|improve this answer























  • Is it possible to edit the file, in spite of creating the new file...
    – abab kren
    Jul 27 at 7:28










  • @ababkren try the second code.
    – SivaPrasath
    Jul 27 at 7:34

















up vote
2
down vote













with reference to the answer.



 awk -F "," 'BEGIN OFS = FS$1="=""$1"""; print' test.csv


we may not know how many fields in a csv. Its quite difficult to declare each field in to print. So better we can edit the field which is required.






share|improve this answer




























    up vote
    0
    down vote













    Since the CSV viewer software seems to be able to detect floating point numbers by the inclusion of a fractional part, the numbers must be converted to have at least one decimal.



    One way of doing this with awk:



    awk -F, -vOFS="," '$1 == int($1) $1 = sprintf("%.1f", $1) 1' file >newfile


    This would test the first comma-separated field to see if it was a whole number. In that case, it would rewrite the field as n.0 (where n is the original number). The trailing 1 in the code would cause all lines to be outputted.



    The result in written to the new file newfile.



    A similar solution using sed:



    sed 's/^([0-9]*),/1.0,/' file >newfile


    Here, we match any number of digits followed immediately by a comma, and replace that with the same digits, .0, and the comma. This would ignore the numbers that already have fractional parts, but would add .0 to numbers that don't have that.






    share|improve this answer























      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f458747%2fhow-to-have-trailing-zero-in-csv%23new-answer', 'question_page');

      );

      Post as a guest






























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      It's purely behavior of CVS viewer which you are using. I'm able to replicate the same issue with MS Excel.



      awk -F "," 'print "=""$1"","$2' test.csv > test3.csv



      • = will force the data to be text.

      To edit the file.



      echo "$(awk -F "," 'print "=""$1"","$2' test.csv)" > test.csv





      share|improve this answer























      • Is it possible to edit the file, in spite of creating the new file...
        – abab kren
        Jul 27 at 7:28










      • @ababkren try the second code.
        – SivaPrasath
        Jul 27 at 7:34














      up vote
      0
      down vote



      accepted










      It's purely behavior of CVS viewer which you are using. I'm able to replicate the same issue with MS Excel.



      awk -F "," 'print "=""$1"","$2' test.csv > test3.csv



      • = will force the data to be text.

      To edit the file.



      echo "$(awk -F "," 'print "=""$1"","$2' test.csv)" > test.csv





      share|improve this answer























      • Is it possible to edit the file, in spite of creating the new file...
        – abab kren
        Jul 27 at 7:28










      • @ababkren try the second code.
        – SivaPrasath
        Jul 27 at 7:34












      up vote
      0
      down vote



      accepted







      up vote
      0
      down vote



      accepted






      It's purely behavior of CVS viewer which you are using. I'm able to replicate the same issue with MS Excel.



      awk -F "," 'print "=""$1"","$2' test.csv > test3.csv



      • = will force the data to be text.

      To edit the file.



      echo "$(awk -F "," 'print "=""$1"","$2' test.csv)" > test.csv





      share|improve this answer















      It's purely behavior of CVS viewer which you are using. I'm able to replicate the same issue with MS Excel.



      awk -F "," 'print "=""$1"","$2' test.csv > test3.csv



      • = will force the data to be text.

      To edit the file.



      echo "$(awk -F "," 'print "=""$1"","$2' test.csv)" > test.csv






      share|improve this answer















      share|improve this answer



      share|improve this answer








      edited Jul 27 at 8:17


























      answered Jul 27 at 7:05









      SivaPrasath

      3,46311535




      3,46311535











      • Is it possible to edit the file, in spite of creating the new file...
        – abab kren
        Jul 27 at 7:28










      • @ababkren try the second code.
        – SivaPrasath
        Jul 27 at 7:34
















      • Is it possible to edit the file, in spite of creating the new file...
        – abab kren
        Jul 27 at 7:28










      • @ababkren try the second code.
        – SivaPrasath
        Jul 27 at 7:34















      Is it possible to edit the file, in spite of creating the new file...
      – abab kren
      Jul 27 at 7:28




      Is it possible to edit the file, in spite of creating the new file...
      – abab kren
      Jul 27 at 7:28












      @ababkren try the second code.
      – SivaPrasath
      Jul 27 at 7:34




      @ababkren try the second code.
      – SivaPrasath
      Jul 27 at 7:34












      up vote
      2
      down vote













      with reference to the answer.



       awk -F "," 'BEGIN OFS = FS$1="=""$1"""; print' test.csv


      we may not know how many fields in a csv. Its quite difficult to declare each field in to print. So better we can edit the field which is required.






      share|improve this answer

























        up vote
        2
        down vote













        with reference to the answer.



         awk -F "," 'BEGIN OFS = FS$1="=""$1"""; print' test.csv


        we may not know how many fields in a csv. Its quite difficult to declare each field in to print. So better we can edit the field which is required.






        share|improve this answer























          up vote
          2
          down vote










          up vote
          2
          down vote









          with reference to the answer.



           awk -F "," 'BEGIN OFS = FS$1="=""$1"""; print' test.csv


          we may not know how many fields in a csv. Its quite difficult to declare each field in to print. So better we can edit the field which is required.






          share|improve this answer













          with reference to the answer.



           awk -F "," 'BEGIN OFS = FS$1="=""$1"""; print' test.csv


          we may not know how many fields in a csv. Its quite difficult to declare each field in to print. So better we can edit the field which is required.







          share|improve this answer













          share|improve this answer



          share|improve this answer











          answered Jul 27 at 17:34









          virtu s

          213




          213




















              up vote
              0
              down vote













              Since the CSV viewer software seems to be able to detect floating point numbers by the inclusion of a fractional part, the numbers must be converted to have at least one decimal.



              One way of doing this with awk:



              awk -F, -vOFS="," '$1 == int($1) $1 = sprintf("%.1f", $1) 1' file >newfile


              This would test the first comma-separated field to see if it was a whole number. In that case, it would rewrite the field as n.0 (where n is the original number). The trailing 1 in the code would cause all lines to be outputted.



              The result in written to the new file newfile.



              A similar solution using sed:



              sed 's/^([0-9]*),/1.0,/' file >newfile


              Here, we match any number of digits followed immediately by a comma, and replace that with the same digits, .0, and the comma. This would ignore the numbers that already have fractional parts, but would add .0 to numbers that don't have that.






              share|improve this answer



























                up vote
                0
                down vote













                Since the CSV viewer software seems to be able to detect floating point numbers by the inclusion of a fractional part, the numbers must be converted to have at least one decimal.



                One way of doing this with awk:



                awk -F, -vOFS="," '$1 == int($1) $1 = sprintf("%.1f", $1) 1' file >newfile


                This would test the first comma-separated field to see if it was a whole number. In that case, it would rewrite the field as n.0 (where n is the original number). The trailing 1 in the code would cause all lines to be outputted.



                The result in written to the new file newfile.



                A similar solution using sed:



                sed 's/^([0-9]*),/1.0,/' file >newfile


                Here, we match any number of digits followed immediately by a comma, and replace that with the same digits, .0, and the comma. This would ignore the numbers that already have fractional parts, but would add .0 to numbers that don't have that.






                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Since the CSV viewer software seems to be able to detect floating point numbers by the inclusion of a fractional part, the numbers must be converted to have at least one decimal.



                  One way of doing this with awk:



                  awk -F, -vOFS="," '$1 == int($1) $1 = sprintf("%.1f", $1) 1' file >newfile


                  This would test the first comma-separated field to see if it was a whole number. In that case, it would rewrite the field as n.0 (where n is the original number). The trailing 1 in the code would cause all lines to be outputted.



                  The result in written to the new file newfile.



                  A similar solution using sed:



                  sed 's/^([0-9]*),/1.0,/' file >newfile


                  Here, we match any number of digits followed immediately by a comma, and replace that with the same digits, .0, and the comma. This would ignore the numbers that already have fractional parts, but would add .0 to numbers that don't have that.






                  share|improve this answer















                  Since the CSV viewer software seems to be able to detect floating point numbers by the inclusion of a fractional part, the numbers must be converted to have at least one decimal.



                  One way of doing this with awk:



                  awk -F, -vOFS="," '$1 == int($1) $1 = sprintf("%.1f", $1) 1' file >newfile


                  This would test the first comma-separated field to see if it was a whole number. In that case, it would rewrite the field as n.0 (where n is the original number). The trailing 1 in the code would cause all lines to be outputted.



                  The result in written to the new file newfile.



                  A similar solution using sed:



                  sed 's/^([0-9]*),/1.0,/' file >newfile


                  Here, we match any number of digits followed immediately by a comma, and replace that with the same digits, .0, and the comma. This would ignore the numbers that already have fractional parts, but would add .0 to numbers that don't have that.







                  share|improve this answer















                  share|improve this answer



                  share|improve this answer








                  edited Jul 27 at 7:12


























                  answered Jul 27 at 7:06









                  Kusalananda

                  101k13199311




                  101k13199311






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f458747%2fhow-to-have-trailing-zero-in-csv%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?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?