LINUX - AWK - make searched lines standout

SCRIPT TO FIND ITEM AND MAKE THAT LINE STANDOUT
###############################################

Find a line you want and append extra text to its right so it stands out from the output

This will keep the output the same it will just append to the line that has the finding in it.
 
textoutput | awk '{ if( $1 ~ /SearchItem/) { print $0, "<===== found you"} else {print $0}}'
 
 
EXAMPLES:
---------
 
Find rpool in zfs listing and make it standout:
zfs list -o space,compressratio,refer | awk '{ if( $1 ~ /rpool/) { print $0, "<===== found you"} else {print $0}}'

NORMAL OUTPUT:
root@kdata516:~# zfs list -o space,compressratio,refer
NAME             AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD  RATIO  REFER
rpool            8.74G  1.10G         0   1.09G              0      2.85M  1.00x  1.09G
vol1             9.68G  3.56T         0   44.0K              0      3.56T  1.18x  44.0K
vol1/._share     10.7G     1G         0   67.9K          1024M          0  1.00x  67.9K
vol1/._system    17.8G  10.0G         0   1.93G          8.07G          0  1.00x  1.93G
vol1/BestLun     14.9G  10.3G         0   5.09G          5.22G          0  1.00x  5.09G
vol1/Test1        142G   135G         0   2.20G           133G          0  2.33x  2.20G
vol1/Three       3.38T  3.37T     21.3K    191M          3.37T          0  1.00x   191M
vol1/lun516      9.68G  5.11G         0   5.11G              0          0  1.00x  5.11G
vol1/lun516snap  17.8G  10.3G         0   2.17G          8.14G          0  2.34x  2.17G
vol1/share1      9.68G  15.3G     30.6K   15.3G              0          0  1.00x  15.3G

WITH AWK:
root@kdata516:~# zfs list -o space,compressratio,refer | awk '{ if( $1 ~ /rpool/) { print $0, "<===== found you"} else {print $0}}'
NAME             AVAIL   USED  USEDSNAP  USEDDS  USEDREFRESERV  USEDCHILD  RATIO  REFER
rpool            8.74G  1.10G         0   1.09G              0      2.85M  1.00x  1.09G <===== found you
vol1             9.68G  3.56T         0   44.0K              0      3.56T  1.18x  44.0K
vol1/._share     10.7G     1G         0   67.9K          1024M          0  1.00x  67.9K
vol1/._system    17.8G  10.0G         0   1.93G          8.07G          0  1.00x  1.93G
vol1/BestLun     14.9G  10.3G         0   5.09G          5.22G          0  1.00x  5.09G
vol1/Test1        142G   135G         0   2.20G           133G          0  2.33x  2.20G
vol1/Three       3.38T  3.37T     21.3K    191M          3.37T          0  1.00x   191M
vol1/lun516      9.68G  5.11G         0   5.11G              0          0  1.00x  5.11G
vol1/lun516snap  17.8G  10.3G         0   2.17G          8.14G          0  2.34x  2.17G
vol1/share1      9.68G  15.3G     30.6K   15.3G              0          0  1.00x  15.3G
 
Find swap word in df output and make that line stand out:
df -h | awk '{ if( $1 ~ /swap/) { print $0, "<===== found you"} else {print $0}}'

NORMAL:
root@kdata516:~# df -h
Filesystem                      Size  Used Avail Use% Mounted on
/devices/ramdisk:a              120M   76M   45M  63% /
vol1                            9.7G   44K  9.7G   1% /vol1
vol1/._share                     11G   68K   11G   1% /vol1/._share
vol1/._system                    20G  2.0G   18G  10% /vol1/._system
vol1/share1                      25G   16G  9.7G  62% /vol1/share1
rpool                           9.9G  1.1G  8.8G  12% /.system
swap                            1.5G  284K  1.5G   1% /etc/svc/volatile
/usr/lib/libc/libc_hwcap1.so.1  9.9G  1.1G  8.8G  12% /lib/libc.so.1
swap                            1.5G  8.0K  1.5G   1% /tmp
swap                            1.5G   17M  1.5G   2% /var/run
/dev/dsk/c0t0d0s0               106M   84M   23M  79% /media/USB DISK


WITH AWK:
root@kdata516:~# df -h | awk '{ if( $1 ~ /swap/) { print $0, "     <===== found you"} else {print $0}}'
Filesystem                      Size  Used Avail Use% Mounted on
/devices/ramdisk:a              120M   76M   45M  63% /
vol1                            9.7G   44K  9.7G   1% /vol1
vol1/._share                     11G   68K   11G   1% /vol1/._share
vol1/._system                    20G  2.0G   18G  10% /vol1/._system
vol1/share1                      25G   16G  9.7G  62% /vol1/share1
rpool                           9.9G  1.1G  8.8G  12% /.system
swap                            1.5G  284K  1.5G   1% /etc/svc/volatile      <===== found you
/usr/lib/libc/libc_hwcap1.so.1  9.9G  1.1G  8.8G  12% /lib/libc.so.1
swap                            1.5G  8.0K  1.5G   1% /tmp      <===== found you
swap                            1.5G   17M  1.5G   2% /var/run      <===== found you
/dev/dsk/c0t0d0s0               106M   84M   23M  79% /media/USB DISK



BONUS:

Looking for multiple things, how to make several things standout - using an OR - kind of like with grep or egrep.

Asking a program to find you item1 or item2, will find both item1 and item2.


Looking for multiple things

command | awk '{ if( $1 ~ (/item1/ || /item2/)) { print $0, "<===== found you"} else {print $0}}'
command | awk '{ if( $1 ~ /item1/) { print $0, "<===== found you"} else {print $0}}'
SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser
Comments