0

Hello I need to add two columns using awk, the colums are made of rational numbers. example:

#/file

20.2 15
15.4 18.4
13.4 14.6

I tried using awk '{print $1+$2}' /file. I seem to be getting integer values (25,43,27). How do I get awk to print rational values?

Nitaa a
  • 121
  • 4
  • 2
    `"{print $1+$2}"` -> `'{print $1+$2}'` – KamilCuk Nov 29 '20 at 13:05
  • 1
    Welcome to SO and thanks for showing your efforts in your question. When I run `awk '{print $1+$2}' Input_file` I get `35.2 33.8 28` which looks to have floating point numbers in its output. Also I am getting a syntax error(with your shown attempts) when I am quoting my `awk` program inside `"` an `awk` program should be quoted with `'.....'`(single quotes). – RavinderSingh13 Nov 29 '20 at 13:06
  • oh sorry I was using '{print $1+$2}' just made a mistake here – Nitaa a Nov 29 '20 at 13:09
  • @Nitaaa, ok, I can't reproduce that issue on liunx, on which O.S you are using or which version of awk? Its always handy to mentioned these kind of details? – RavinderSingh13 Nov 29 '20 at 13:10
  • I am sorry, I am very new to linux, programing and stackoverflow. mawk 1.3.4 20200120 Copyright 2008-2019,2020, Thomas E. Dickey Copyright 1991-1996,2014, Michael D. Brennan random-funcs: srandom/random regex-funcs: internal compiled limits: sprintf buffer 8192 maximum-integer 2147483647, and I am using ubuntu 20.04.01 LTS – Nitaa a Nov 29 '20 at 13:15

0 Answers0