How to have trailing zero in CSV
Clash 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
linux csv sendmail
add a comment |Â
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
linux csv sendmail
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
add a comment |Â
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
linux csv sendmail
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
linux csv sendmail
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
add a comment |Â
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
add a comment |Â
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
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Jul 27 at 17:34
virtu s
213
213
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited Jul 27 at 7:12
answered Jul 27 at 7:06
Kusalananda
101k13199311
101k13199311
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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