I have tried a bunch of different methods to get the out come I am looking for but not having any luck.
awk '{if ($10 == "Available") print substr ($8, 11) " is online"; else print substr ($8, 11) " is offline"}' status.txt
I need the "online" in green and the "offline" in red. Any simple ways to achieve this?
CodePudding user response:
You can try this
$ awk '{if ($10 == "Available") print substr ($8, 11) "\033[32m is online\033[0m"; else print substr ($8, 11) "\033[31m is offline\033[0m"}' input_file
Or
$ awk -v red="$(tput setaf 1)" -v green="$(tput setaf 2)" -v zero="$(tput sgr0)" '{if ($10 == "Available") print substr ($8, 11) green" is online"zero; else print substr ($8, 11) red" is offline"zero}' input_file