gnulyn
1
Dear ALL,
I have sample file :
tx_bytes: 2422,
tx_packets: 13,
uptime: 16119,
tx_bytes: 2342,
tx_packets: 14,
uptime: 11009,
tx_bytes: 252,
tx_packets: 12,
uptime: 3113,
my formula :
minutes=$(( uptime/60%60 ))
hours=$(( uptime/60/60%24 ))
required output:
tx_bytes: 2422,
tx_packets: 13,
uptime: 4:28,
tx_bytes: 2342,
tx_packets: 14,
uptime: 3:3,
tx_bytes: 252,
tx_packets: 12,
uptime: 0:51,
Can you help me pls..
Not sure what you are after but this is longhand for one value:-
OSX 10.12.4, default bash terminal.
Last login: Fri Apr 14 16:52:28 on ttys000
AMIGA:barrywalker~> uptime=16119
AMIGA:barrywalker~> minutes=$(( uptime/60 ))
AMIGA:barrywalker~> echo $minutes
268
AMIGA:barrywalker~> hours=$(( minutes/60 ))
AMIGA:barrywalker~> echo $hours
4
AMIGA:barrywalker~> minutes=$(( minutes - ( hours * 60 ) ))
AMIGA:barrywalker~> echo $minutes
28
AMIGA:barrywalker~> uptime="$hours:$minutes"
AMIGA:barrywalker~> echo $uptime
4:28
AMIGA:barrywalker~> _
awk '$1=="uptime:" {$2=sprintf("%02d:%02d,", $2/60/60%24, $2/60%60) }1' myFile
1 Like
gnulyn
4
Thanks for vgersh99
[root@localhost ~]# ./forum.sh
tx_bytes: 2422,
tx_packets: 13,
uptime: 04:28,
tx_bytes: 2342,
tx_packets: 14,
uptime: 03:03,
tx_bytes: 252,
tx_packets: 12,
uptime: 00:51,
[root@localhost ~]#