So what I've been trying to do is replace a certain output in bash with awk. But I can't seem to get it to work. I'm trying to replace the $6 output from "uptime" to 'user' instead of 'users'. How can this be done with awk or sed?
This is a "part" of my current script.
#!/bin/bash
since="`uptime --since`"
start="`date --date "$since" '+%s'`"
now="`date '+%s'`"
sec=$((now-start))
days=$((sec/(60*60*24)))
sec=$((sec-days*(60*60*24)))
hr=$((sec/(60*60)))
sec=$((sec-hr*(60*60)))
min=$((sec/60))
sec=$((sec-min*60))
rest="$(uptime | perl -npe'{s/(.*,\s+)(\d+\s+use)/$2/}')"
printf `uptime | awk '{print $1}'`" up %2d:%02d, %s\n" $hr $min "$rest"
The output is as following 21:08:13 up 0:10, 3 users load average: 0.30, 0.30, 0.25
uptime | awk '{ sub("users,","user,") }1'