Reputation: 23
I have two AWK commands that do the equivalent of grep -e PATTERN
and the other colors specific words in the output but doesn't filter only those lines. Can they be combined into one awk.sh file?
This one prints 3 variables (Username, Group Policy, and Assigned IP) :
awk '/^Username/{print $0}/^Group/{print $0}/^Assigned/{print $0}' session.log
So it looks like this:
[root@localhost User]# ./find.sh
Username : User1 Index : 111
Assigned IP : 11.11.11.111 Public IP : 22.22.22.222
Group Policy : DfltGrpPolicy Tunnel Group : Default-VPN
Username : User2 Index : 111
Assigned IP : 11.11.11.111 Public IP : 22.22.22.222
Group Policy : DfltGrpPolicy Tunnel Group : Default-VPN
The other colors those variables green and red respectively (but outputs a lot of junk, and for some reason the coloring is broken on the second variable?):
cat session.log | awk '{ gsub("Username", "\033[1;32m&\033[0m");
gsub("Assigned IP", "\033[1;32m&\032[0m");
gsub("Group Policy", "\033[1;31m&\033[0m");
print }'
Here is the picture of colouring output:
And here is the edited in MS Word, but this is my end goal.
Upvotes: 1
Views: 241
Reputation: 16948
sub
instead of gsub
.\032[0m
but I guess you wanted \033[0m
.You can combine everything:
awk '/^(Username|Assigned IP)/{sub("^(Username|Assigned IP)", "\033[1;32m&\033[0m"); print} /^Group Policy/{sub("^Group Policy", "\033[1;31m&\033[0m"); print}' session.log
Upvotes: 1