Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • I do appreciate the answer and I'll lean a lot about awk from this, but I'd really rather a solution that did not try to do the math involved because the number formats are far more complex than this simplistic example. I have different commodities with localized formats including thousand separators is some that are decimal separators in others, RTL scripts in the units, etc. I'd rather not try to validate a round trip between localized and normalized formats. Commented Jun 27, 2019 at 7:25
  • @Caleb in that case, how can I determine that the number is negative? Would just checking for - in the number be sufficient? Or do you have negative numbers that use the financial way (50) instead of -50? Commented Jun 27, 2019 at 7:29
  • Good question. And actually yes, matching - anywhere in the amount field is sufficient, that is universal although it's position in the amount changes with localization. Commented Jun 27, 2019 at 7:31
  • Thanks, and thanks for the code comments! It's actually a lot more convoluted in awk than I expected when I asked this and I'm not sure if I wouldn't have been better off just writing a parsing script, but it does what I wanted and I learned a few things along the way. Commented Jun 27, 2019 at 7:56
  • 1
    @Caleb usually awk ignores leading spaces, but not when you set a custom FS. So $1 and $2 would now actually be $2 and $3 (the first field being empty). Commented Jun 27, 2019 at 10:54