print a column with the desire format output [closed]
I have a list of the following data in a file:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
and I am trying to align all data so to have:
-0.347689000000000
0.0743938333333333
-1.099024000000000
0.0743938333333333
-0.216910000000000
0.0879397500000000
unfortunately I couldn't make it with awk '{printf "%18sn", $1}'
. The ideal is to have an output like this:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
awk text-formatting printf
closed as unclear what you're asking by G-Man, peterh, Jeff Schaller, A.B, Inian Dec 28 '18 at 5:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have a list of the following data in a file:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
and I am trying to align all data so to have:
-0.347689000000000
0.0743938333333333
-1.099024000000000
0.0743938333333333
-0.216910000000000
0.0879397500000000
unfortunately I couldn't make it with awk '{printf "%18sn", $1}'
. The ideal is to have an output like this:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
awk text-formatting printf
closed as unclear what you're asking by G-Man, peterh, Jeff Schaller, A.B, Inian Dec 28 '18 at 5:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Your question says “I am trying to have X; the ideal is to have Y.” What do you want? Describe it in words. Do you want the strings to be left aligned, so the-
in front of negative numbers lines up with the first digit of non-negative numbers? Do you want the numbers lined up on the.
? Do you want the strings to be right-aligned? Do you want to truncate digits from the right? Will you ever have an entry like.142857
(with no leading zero)? Will you ever have a number ≥ 10 (i.e., more than one digit)?
– G-Man
Dec 23 '18 at 22:40
P.S. Every line of your sample file has 17 digits, where the rightmost 8 digits are the same. This is very hard to read. In the future, please present questions with data that can be looked at and understood.
– G-Man
Dec 23 '18 at 22:40
add a comment |
I have a list of the following data in a file:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
and I am trying to align all data so to have:
-0.347689000000000
0.0743938333333333
-1.099024000000000
0.0743938333333333
-0.216910000000000
0.0879397500000000
unfortunately I couldn't make it with awk '{printf "%18sn", $1}'
. The ideal is to have an output like this:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
awk text-formatting printf
I have a list of the following data in a file:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
and I am trying to align all data so to have:
-0.347689000000000
0.0743938333333333
-1.099024000000000
0.0743938333333333
-0.216910000000000
0.0879397500000000
unfortunately I couldn't make it with awk '{printf "%18sn", $1}'
. The ideal is to have an output like this:
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
awk text-formatting printf
awk text-formatting printf
edited Dec 23 '18 at 18:57
Jeff Schaller
42.9k1159137
42.9k1159137
asked Dec 23 '18 at 16:59
Dimitris MintisDimitris Mintis
805
805
closed as unclear what you're asking by G-Man, peterh, Jeff Schaller, A.B, Inian Dec 28 '18 at 5:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by G-Man, peterh, Jeff Schaller, A.B, Inian Dec 28 '18 at 5:50
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Your question says “I am trying to have X; the ideal is to have Y.” What do you want? Describe it in words. Do you want the strings to be left aligned, so the-
in front of negative numbers lines up with the first digit of non-negative numbers? Do you want the numbers lined up on the.
? Do you want the strings to be right-aligned? Do you want to truncate digits from the right? Will you ever have an entry like.142857
(with no leading zero)? Will you ever have a number ≥ 10 (i.e., more than one digit)?
– G-Man
Dec 23 '18 at 22:40
P.S. Every line of your sample file has 17 digits, where the rightmost 8 digits are the same. This is very hard to read. In the future, please present questions with data that can be looked at and understood.
– G-Man
Dec 23 '18 at 22:40
add a comment |
1
Your question says “I am trying to have X; the ideal is to have Y.” What do you want? Describe it in words. Do you want the strings to be left aligned, so the-
in front of negative numbers lines up with the first digit of non-negative numbers? Do you want the numbers lined up on the.
? Do you want the strings to be right-aligned? Do you want to truncate digits from the right? Will you ever have an entry like.142857
(with no leading zero)? Will you ever have a number ≥ 10 (i.e., more than one digit)?
– G-Man
Dec 23 '18 at 22:40
P.S. Every line of your sample file has 17 digits, where the rightmost 8 digits are the same. This is very hard to read. In the future, please present questions with data that can be looked at and understood.
– G-Man
Dec 23 '18 at 22:40
1
1
Your question says “I am trying to have X; the ideal is to have Y.” What do you want? Describe it in words. Do you want the strings to be left aligned, so the
-
in front of negative numbers lines up with the first digit of non-negative numbers? Do you want the numbers lined up on the .
? Do you want the strings to be right-aligned? Do you want to truncate digits from the right? Will you ever have an entry like .142857
(with no leading zero)? Will you ever have a number ≥ 10 (i.e., more than one digit)?– G-Man
Dec 23 '18 at 22:40
Your question says “I am trying to have X; the ideal is to have Y.” What do you want? Describe it in words. Do you want the strings to be left aligned, so the
-
in front of negative numbers lines up with the first digit of non-negative numbers? Do you want the numbers lined up on the .
? Do you want the strings to be right-aligned? Do you want to truncate digits from the right? Will you ever have an entry like .142857
(with no leading zero)? Will you ever have a number ≥ 10 (i.e., more than one digit)?– G-Man
Dec 23 '18 at 22:40
P.S. Every line of your sample file has 17 digits, where the rightmost 8 digits are the same. This is very hard to read. In the future, please present questions with data that can be looked at and understood.
– G-Man
Dec 23 '18 at 22:40
P.S. Every line of your sample file has 17 digits, where the rightmost 8 digits are the same. This is very hard to read. In the future, please present questions with data that can be looked at and understood.
– G-Man
Dec 23 '18 at 22:40
add a comment |
3 Answers
3
active
oldest
votes
Maybe too small a field width. Try
awk '{printf "%19sn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
add a comment |
Both GNU Awk (gawk
) and mawk
appear to support the C printf
' '
modifier that adds a space in front of positive numbers to align them with negative ones
' ' (a space) A blank should be left before a positive number (or
empty string) produced by a signed conversion.
So for example:
$ mawk '{printf "% 22.16fn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Alternatively, with numfmt
$ numfmt --format='% 22.16f' < file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
As far as I can tell, this is equivalent to%22.16f
(without the space) except, with% 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.
– G-Man
Dec 23 '18 at 22:41
add a comment |
you can also use printf(1)
:
xargs <file printf '%19.16fn'
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
or, if the input file isn't too big, the printf
shell built-in:
undef IFS
printf '%19.16fn' $(cat file)
Strictly speaking, if you're running it throughxargs
, you aren't running the builtin.
– G-Man
Dec 23 '18 at 18:48
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Maybe too small a field width. Try
awk '{printf "%19sn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
add a comment |
Maybe too small a field width. Try
awk '{printf "%19sn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
add a comment |
Maybe too small a field width. Try
awk '{printf "%19sn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Maybe too small a field width. Try
awk '{printf "%19sn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
answered Dec 23 '18 at 17:12
RudiCRudiC
4,2541312
4,2541312
add a comment |
add a comment |
Both GNU Awk (gawk
) and mawk
appear to support the C printf
' '
modifier that adds a space in front of positive numbers to align them with negative ones
' ' (a space) A blank should be left before a positive number (or
empty string) produced by a signed conversion.
So for example:
$ mawk '{printf "% 22.16fn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Alternatively, with numfmt
$ numfmt --format='% 22.16f' < file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
As far as I can tell, this is equivalent to%22.16f
(without the space) except, with% 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.
– G-Man
Dec 23 '18 at 22:41
add a comment |
Both GNU Awk (gawk
) and mawk
appear to support the C printf
' '
modifier that adds a space in front of positive numbers to align them with negative ones
' ' (a space) A blank should be left before a positive number (or
empty string) produced by a signed conversion.
So for example:
$ mawk '{printf "% 22.16fn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Alternatively, with numfmt
$ numfmt --format='% 22.16f' < file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
As far as I can tell, this is equivalent to%22.16f
(without the space) except, with% 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.
– G-Man
Dec 23 '18 at 22:41
add a comment |
Both GNU Awk (gawk
) and mawk
appear to support the C printf
' '
modifier that adds a space in front of positive numbers to align them with negative ones
' ' (a space) A blank should be left before a positive number (or
empty string) produced by a signed conversion.
So for example:
$ mawk '{printf "% 22.16fn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Alternatively, with numfmt
$ numfmt --format='% 22.16f' < file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Both GNU Awk (gawk
) and mawk
appear to support the C printf
' '
modifier that adds a space in front of positive numbers to align them with negative ones
' ' (a space) A blank should be left before a positive number (or
empty string) produced by a signed conversion.
So for example:
$ mawk '{printf "% 22.16fn", $1}' file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
Alternatively, with numfmt
$ numfmt --format='% 22.16f' < file
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
answered Dec 23 '18 at 17:45
steeldriversteeldriver
36.6k35287
36.6k35287
As far as I can tell, this is equivalent to%22.16f
(without the space) except, with% 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.
– G-Man
Dec 23 '18 at 22:41
add a comment |
As far as I can tell, this is equivalent to%22.16f
(without the space) except, with% 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.
– G-Man
Dec 23 '18 at 22:41
As far as I can tell, this is equivalent to
%22.16f
(without the space) except, with % 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.– G-Man
Dec 23 '18 at 22:41
As far as I can tell, this is equivalent to
%22.16f
(without the space) except, with % 22.16f
(with the space), numbers ≥ 10000 will have an extra space added in front, so they line up with numbers ≤ −10000, but not with numbers strictly between −10000 and 10000. This might or might not be what the OP wants.– G-Man
Dec 23 '18 at 22:41
add a comment |
you can also use printf(1)
:
xargs <file printf '%19.16fn'
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
or, if the input file isn't too big, the printf
shell built-in:
undef IFS
printf '%19.16fn' $(cat file)
Strictly speaking, if you're running it throughxargs
, you aren't running the builtin.
– G-Man
Dec 23 '18 at 18:48
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
add a comment |
you can also use printf(1)
:
xargs <file printf '%19.16fn'
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
or, if the input file isn't too big, the printf
shell built-in:
undef IFS
printf '%19.16fn' $(cat file)
Strictly speaking, if you're running it throughxargs
, you aren't running the builtin.
– G-Man
Dec 23 '18 at 18:48
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
add a comment |
you can also use printf(1)
:
xargs <file printf '%19.16fn'
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
or, if the input file isn't too big, the printf
shell built-in:
undef IFS
printf '%19.16fn' $(cat file)
you can also use printf(1)
:
xargs <file printf '%19.16fn'
-0.3476890000000000
0.0743938333333333
-1.0990240000000000
0.0743938333333333
-0.2169100000000000
0.0879397500000000
or, if the input file isn't too big, the printf
shell built-in:
undef IFS
printf '%19.16fn' $(cat file)
edited Dec 23 '18 at 19:01
answered Dec 23 '18 at 18:20
Uncle BillyUncle Billy
6496
6496
Strictly speaking, if you're running it throughxargs
, you aren't running the builtin.
– G-Man
Dec 23 '18 at 18:48
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
add a comment |
Strictly speaking, if you're running it throughxargs
, you aren't running the builtin.
– G-Man
Dec 23 '18 at 18:48
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
Strictly speaking, if you're running it through
xargs
, you aren't running the builtin.– G-Man
Dec 23 '18 at 18:48
Strictly speaking, if you're running it through
xargs
, you aren't running the builtin.– G-Man
Dec 23 '18 at 18:48
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
@G-Man right, and that's not "simply speaking". It was "simply wrong"; xargs cannot run shell built-ins.
– Uncle Billy
Dec 23 '18 at 19:04
add a comment |
1
Your question says “I am trying to have X; the ideal is to have Y.” What do you want? Describe it in words. Do you want the strings to be left aligned, so the
-
in front of negative numbers lines up with the first digit of non-negative numbers? Do you want the numbers lined up on the.
? Do you want the strings to be right-aligned? Do you want to truncate digits from the right? Will you ever have an entry like.142857
(with no leading zero)? Will you ever have a number ≥ 10 (i.e., more than one digit)?– G-Man
Dec 23 '18 at 22:40
P.S. Every line of your sample file has 17 digits, where the rightmost 8 digits are the same. This is very hard to read. In the future, please present questions with data that can be looked at and understood.
– G-Man
Dec 23 '18 at 22:40