awk or sed: change the color of a column w/o screwing up column spacing
Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately.
Here's some example output:
I'd like to colorize the output as well -- it's easy enough to change the color of the header line, but the other piece I can't figure out is: changing the color of the interface name, i.e., the first field of line 2+.
Now, in a perfect world I would have my awk script generate the color and columnize the output but I haven't tried to figure out columnizing in awk yet -- it doesn't look easy. Here's what I did to colorize the first line:
This won't work for the additional lines (i.e. the ones where I just want to change the color of $1), because as soon as I start picking out fields, I'll lose the carefully-crafted whitespace separating said fields.
I think sed is what I need... I suspect with the right switches it should be able to
operate on NR >= 2
regex replace the first word of each record with <color>&<color>
Any ideas will be greatly appreciated.
PS: I have an application I'm working on that uses tons of awk "modules" to do this kind of parsing of output. Some of them also pipe their output to column for the final display as well. If you know of any good resources on awk columnizing, I'd love to see 'em. Here's another example:
That's generated by 2 awk commands piped to column. And currently, after that I pipe it to another awk to change the color of each line -- orange if the link is down and green if it's up. I'm happy with that, but I might prefer to change just the link=DOWN or link=UP part -- but again, I don't see how to do it without screwing up the spacing.
---------- Post updated at 06:20 AM ---------- Previous update was at 02:54 AM ----------
I spent a few hours working on other things and then it just hit me -- I could use awk's gensub() for this. I'd still love to learn more about awk columnizing, but ....
I don't think the col width is known in advance, in above example it ranges from 6 to 8, and even the header would not be a reliable indicator as you see in the Iface col. column does a fine job here, and it is not that easy to keep the col alignment intact.
input
"A","B","C,D","E","F"
"S","T","U,V","W","X"
"AA","BB","CC,DD","EEEE","FFF"
required output:
"A","B","C,D","C,D","F"
"S", T","U,V","U,V","X"
"AA","BB","CC,DD","CC,DD","FFF"
tried using awk but double quotes not preserving for every field. any help to solve this is much... (5 Replies)
Hi,
My input files is like this
axis1 0 1 10
axis2 0 1 5
axis1 1 2 -4
axis2 2 3 -3
axis1 3 4 5
axis2 3 4 -1
axis1 4 5 -6
axis2 4 5 1
Now, these are my following tasks
1. Print a first column for every two rows that has the same value followed by a string.
2. Match on the... (3 Replies)
Hi Guys,
Input.txt
L194 A -118.2
L194 B -115.1
L194 C -118.7
L196 A 0
L196 C 0
L197 A -111.2
L197 B -118.9
L197 C -119.9
L199 A -120.4
L199 B -119.9 ... (2 Replies)
Hi Gurus,
I have file content sample:
,5113955056,,TAgent-Suspend
,5119418233,,TAgent-Suspend
,5102119078,,TAgent-Suspend
filenames 120229H5_suspend, 120229H6_unsuspend
I receive those files one of directory /home/temp/
I need following:
1. Backup first /home/temp/ file to... (5 Replies)
Hi;
I've been searching posts to find a solution to what I'm trying to do, but I've have NOT found anything yet.
I have a file (file1) with 300K columns and 1411 rows, the columns don't have a column no. header (No header at all) and I'm trying to fetch the information from specific columns.... (3 Replies)
If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output).
Thanx
input1
1 a aaaaa +
2 b bbbbb +
3 c ccccc +
4 d ddddd +
5 e eeeee +
6 f xxxxx +
8 h hhhhh +... (8 Replies)
$ cat log.txt
Name Age Sex Lcation nfld alias xsd
CC 25 M XYZ asx KK Y
BB 21 F XAS awe SS N
SD 21 M AQW rty SD A
How can I replace the column with header "Lcation" with the column with header "alias" and delete the "alias" column?
so that the final output will become:
Name Age Sex... (10 Replies)
Is there way to use sed to change only one occurence in a colon separated line?
I would like to change a file from
*:*:rex:rex
*:*:simon:rex
to
*:*:rex:mabry
*:*:simon:rex (2 Replies)