Thousand separator in awk

Archemar

I would like to print thousand separator with awk's printf.

In bash, it is pretty straightforward:

> printf "a %'d b \n" 1234567
a 1,234,567 b
> LC_NUMERIC=fr_FR.utf8
> printf "a %'d b \n" 1234567
a 1 234 567 b

With an awk program it almost worked:

> cat > print.awk
{ printf "a %'d b\n",$1}
> echo 1234567 | awk -f print.awk
a 1,234,567 b

(Locale seems to be lost ... )

And in command line:

> echo 1234567 | awk '{printf "%d\n",$1;}'
1234567
> echo 1234567 | awk '{printf "%'d\n",$1;}'
> echo 1234567 | awk '{printf "%\'d\n",$1;}'

Note

I have a workaround, I just want to use %'d if possible.

cuonglm

Just use a variable to hold ':

echo 1234567 | q="'" awk '{printf "%"ENVIRON["q"]"d\n", $1}'
1,234,567

or use \047 to represent ':

echo 1234567 | awk '{printf "%\047d\n", $1}'

This will work in any POSIX awk (not work with mawk).

With gawk:

echo 1234567 | awk '{printf "%""\x27""d\n", $1}'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Thousand Separator in DBGrid

From Dev

Devexpress XRtableCell thousand separator?

From Dev

validate decimal with decimal separator and thousand separator

From Dev

How to format number with "." as thousand separator, and "," as decimal separator?

From Dev

Set global thousand separator on knitr

From Dev

Regex valid numbers with thousand separator

From Dev

Format number with space as thousand separator

From Dev

Thousand separator not working right way

From Dev

Adding Thousand Separator to Int in Swift

From Dev

Remove thousand separator from string

From Dev

dot instead of comma as thousand separator

From Dev

Thousand separator with wide/unicode stream

From Dev

Regex valid numbers with thousand separator

From Dev

Thousand separator not working right way

From Dev

Adding thousand separator to jQuery Counter

From Dev

Format number with space as thousand separator

From Dev

Adding Thousand Separator Automatically (Swift)

From Dev

String Number format with "/" for thousand separator

From Dev

d3.format thousand separator on variables?

From Dev

Formatting thousand separator for integers in a pandas dataframe

From Dev

Decimal not showing group(thousand) separator after parse

From Dev

regex for multiple formats decimals and thousand separator

From Dev

ExtJS 6 thousand separator in number field

From Dev

Is it possible to print a number formatted with thousand separator in Rust?

From Dev

Python replace middle digits with commas thousand separator

From Dev

Adding thousand separator while printing a number

From Dev

Regular expression for thousand separator without decimal point

From Dev

Format a bootstrap table with dollar sign and thousand separator

From Dev

Only add thousand separator before decimal comma

Related Related

  1. 1

    Thousand Separator in DBGrid

  2. 2

    Devexpress XRtableCell thousand separator?

  3. 3

    validate decimal with decimal separator and thousand separator

  4. 4

    How to format number with "." as thousand separator, and "," as decimal separator?

  5. 5

    Set global thousand separator on knitr

  6. 6

    Regex valid numbers with thousand separator

  7. 7

    Format number with space as thousand separator

  8. 8

    Thousand separator not working right way

  9. 9

    Adding Thousand Separator to Int in Swift

  10. 10

    Remove thousand separator from string

  11. 11

    dot instead of comma as thousand separator

  12. 12

    Thousand separator with wide/unicode stream

  13. 13

    Regex valid numbers with thousand separator

  14. 14

    Thousand separator not working right way

  15. 15

    Adding thousand separator to jQuery Counter

  16. 16

    Format number with space as thousand separator

  17. 17

    Adding Thousand Separator Automatically (Swift)

  18. 18

    String Number format with "/" for thousand separator

  19. 19

    d3.format thousand separator on variables?

  20. 20

    Formatting thousand separator for integers in a pandas dataframe

  21. 21

    Decimal not showing group(thousand) separator after parse

  22. 22

    regex for multiple formats decimals and thousand separator

  23. 23

    ExtJS 6 thousand separator in number field

  24. 24

    Is it possible to print a number formatted with thousand separator in Rust?

  25. 25

    Python replace middle digits with commas thousand separator

  26. 26

    Adding thousand separator while printing a number

  27. 27

    Regular expression for thousand separator without decimal point

  28. 28

    Format a bootstrap table with dollar sign and thousand separator

  29. 29

    Only add thousand separator before decimal comma

HotTag

Archive