1

I live in Holland and currency is stated with a komma (,) instead of a dot (.) I.e.feeds with 14.95 is interpreted as a number instead of 14,95 in euros

Is there a LINUX command (sed?) which can solve this problem? So 14.95 is changed into 14,95

I've tried to replace the dot with a komma but the feed has a number of correct dot's which are also replaced

Peter
  • 53
  • 1
  • 7

4 Answers4

0

Assuming the legitimate full stops are in other fields you could use awk to change only the currency field and ignore any "." in other fields. Here is an inline example where the currency is in field 2:

echo "field1 19.45 field3" | awk '{gsub("\\.",",",$2);print $0}'

You can do the same with an input file,

awk '{gsub("\\.",",",$2);print $0}' in_file > out_file
Geraint Anderson
  • 3,234
  • 4
  • 28
  • 49
  • Your option from a file didn't work (other option I didn't try) – Peter Jul 16 '15 at 15:04
  • Did you change "in_file" for your actual file name? And did you change $2 to the field number in the file? What delimiters are you using? If you need too change it from whitespace you can use `-F"d"` where d is the delimiter. Perhaps we could help more if you could share a line from the file? – Geraint Anderson Jul 16 '15 at 20:27
0

If all your entries are in file, you could do

cat file | awk -F\. '{print $1","$2}' > newfile
rickydj
  • 629
  • 5
  • 17
0

This sed command replaces '.' between digits with a comma (komma)

sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)/\1,\2/'
ramana_k
  • 1,933
  • 2
  • 10
  • 14
0

If you use setlocale, you just have to use the following at the program entry point (at the beginning of main()):

#include <locale.h>
...
int main (int argc, char **argv)
{
    setlocale(LC_ALL, "");
    ...

(of course, you can use setlocale(LC_NUMERIC, ""); to only affect numeric printing)

to get printf() and cousins begin printing decimal point in the locale you reside in (of course, if you have it configured in your environment). See the manpage for full documentation.

Luis Colorado
  • 10,974
  • 1
  • 16
  • 31