5

I was searching and trying a lot of different approaches, but non of them really did what I need. Hopefully it was not asked million times before.

I have this alias in my bashrc:

alias temp='awk '\''{ printf ("%0.1f",$1/1000); }'\'' < /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input'

output of it is:

measure@remote ~ $ temp
10.6measure@remote ~ $

what I'm trying to achieve is ouput like this:

measure@remote ~ $ temp
10.6
measure@remote ~ $
Inian
  • 80,270
  • 14
  • 142
  • 161
fluffypuffy
  • 103
  • 1
  • 1
  • 6

3 Answers3

8

Replace

"%0.1f"

with

"%0.1f\n"
Cyrus
  • 84,225
  • 14
  • 89
  • 153
5

Generic answer to how to add new line at the end with awk would be:

$ awk '... END{print "\n"}'  # or print ORS
James Brown
  • 36,089
  • 7
  • 43
  • 59
  • 2
    @EdMorton I stand corrected. I'll leave this unedited for a while for self shaming on not thinking it through before posting (then again, it _adds a new line ..._). – James Brown Jan 27 '18 at 13:18
3

Never use an alias for substituting a command and especially ones involving nested quotes like this. Just use a function in .bashrc to simplify it

get_ratio() {
    awk '{ printf ("%0.1f\n",$1/1000); }' /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input
}

and call it from the command line

measure@remote ~ $ source ~/.bashrc
measure@remote ~ $ get_ratio
Inian
  • 80,270
  • 14
  • 142
  • 161