AWK print and color 3 variables
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
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", "33[1;32m&33[0m");
gsub("Assigned IP", "33[1;32m&32[0m");
gsub("Group Policy", "33[1;31m&33[0m");
print }'
Here is the picture of colouring output:
And here is the edited in MS Word, but this is my end goal.
bash awk
add a comment |
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", "33[1;32m&33[0m");
gsub("Assigned IP", "33[1;32m&32[0m");
gsub("Group Policy", "33[1;31m&33[0m");
print }'
Here is the picture of colouring output:
And here is the edited in MS Word, but this is my end goal.
bash awk
Welcome to SO, good that you have shown us what you have tried. Request you to please post sample input and sample output in your post with code tags and let us know then?
– RavinderSingh13
Nov 26 '18 at 17:18
add a comment |
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", "33[1;32m&33[0m");
gsub("Assigned IP", "33[1;32m&32[0m");
gsub("Group Policy", "33[1;31m&33[0m");
print }'
Here is the picture of colouring output:
And here is the edited in MS Word, but this is my end goal.
bash awk
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", "33[1;32m&33[0m");
gsub("Assigned IP", "33[1;32m&32[0m");
gsub("Group Policy", "33[1;31m&33[0m");
print }'
Here is the picture of colouring output:
And here is the edited in MS Word, but this is my end goal.
bash awk
bash awk
edited Nov 26 '18 at 23:12
kit
1,10631017
1,10631017
asked Nov 26 '18 at 16:59
JakobJakob
132
132
Welcome to SO, good that you have shown us what you have tried. Request you to please post sample input and sample output in your post with code tags and let us know then?
– RavinderSingh13
Nov 26 '18 at 17:18
add a comment |
Welcome to SO, good that you have shown us what you have tried. Request you to please post sample input and sample output in your post with code tags and let us know then?
– RavinderSingh13
Nov 26 '18 at 17:18
Welcome to SO, good that you have shown us what you have tried. Request you to please post sample input and sample output in your post with code tags and let us know then?
– RavinderSingh13
Nov 26 '18 at 17:18
Welcome to SO, good that you have shown us what you have tried. Request you to please post sample input and sample output in your post with code tags and let us know then?
– RavinderSingh13
Nov 26 '18 at 17:18
add a comment |
1 Answer
1
active
oldest
votes
- You don't need cat to read the file. Just use awk.
- I think you want to
sub
instead ofgsub
. - In Assigned IP, you have
32[0m
but I guess you wanted33[0m
.
You can combine everything:
awk '/^(Username|Assigned IP)/{sub("^(Username|Assigned IP)", "33[1;32m&33[0m"); print} /^Group Policy/{sub("^Group Policy", "33[1;31m&33[0m"); print}' session.log
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
@Jakob You're welcome.gsub
is the g lobal version ofsub
, it replaces all occurences instead of the first one.
– steffen
Nov 26 '18 at 17:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53485800%2fawk-print-and-color-3-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- You don't need cat to read the file. Just use awk.
- I think you want to
sub
instead ofgsub
. - In Assigned IP, you have
32[0m
but I guess you wanted33[0m
.
You can combine everything:
awk '/^(Username|Assigned IP)/{sub("^(Username|Assigned IP)", "33[1;32m&33[0m"); print} /^Group Policy/{sub("^Group Policy", "33[1;31m&33[0m"); print}' session.log
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
@Jakob You're welcome.gsub
is the g lobal version ofsub
, it replaces all occurences instead of the first one.
– steffen
Nov 26 '18 at 17:31
add a comment |
- You don't need cat to read the file. Just use awk.
- I think you want to
sub
instead ofgsub
. - In Assigned IP, you have
32[0m
but I guess you wanted33[0m
.
You can combine everything:
awk '/^(Username|Assigned IP)/{sub("^(Username|Assigned IP)", "33[1;32m&33[0m"); print} /^Group Policy/{sub("^Group Policy", "33[1;31m&33[0m"); print}' session.log
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
@Jakob You're welcome.gsub
is the g lobal version ofsub
, it replaces all occurences instead of the first one.
– steffen
Nov 26 '18 at 17:31
add a comment |
- You don't need cat to read the file. Just use awk.
- I think you want to
sub
instead ofgsub
. - In Assigned IP, you have
32[0m
but I guess you wanted33[0m
.
You can combine everything:
awk '/^(Username|Assigned IP)/{sub("^(Username|Assigned IP)", "33[1;32m&33[0m"); print} /^Group Policy/{sub("^Group Policy", "33[1;31m&33[0m"); print}' session.log
- You don't need cat to read the file. Just use awk.
- I think you want to
sub
instead ofgsub
. - In Assigned IP, you have
32[0m
but I guess you wanted33[0m
.
You can combine everything:
awk '/^(Username|Assigned IP)/{sub("^(Username|Assigned IP)", "33[1;32m&33[0m"); print} /^Group Policy/{sub("^Group Policy", "33[1;31m&33[0m"); print}' session.log
answered Nov 26 '18 at 17:17
steffensteffen
9,53322458
9,53322458
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
@Jakob You're welcome.gsub
is the g lobal version ofsub
, it replaces all occurences instead of the first one.
– steffen
Nov 26 '18 at 17:31
add a comment |
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
@Jakob You're welcome.gsub
is the g lobal version ofsub
, it replaces all occurences instead of the first one.
– steffen
Nov 26 '18 at 17:31
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
That was exactly what I was looking for. Thank you so much. 1. My mistake, noob error 2. Is gsub the wrong variable? Will be looking into this more for my own sake. 3. Yes, Typo when I was changing color values :)
– Jakob
Nov 26 '18 at 17:23
@Jakob You're welcome.
gsub
is the g lobal version of sub
, it replaces all occurences instead of the first one.– steffen
Nov 26 '18 at 17:31
@Jakob You're welcome.
gsub
is the g lobal version of sub
, it replaces all occurences instead of the first one.– steffen
Nov 26 '18 at 17:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53485800%2fawk-print-and-color-3-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to SO, good that you have shown us what you have tried. Request you to please post sample input and sample output in your post with code tags and let us know then?
– RavinderSingh13
Nov 26 '18 at 17:18