Answer the question
In order to leave comments, you need to log in
How to highlight certain words in the output of a bash script?
Tell me please.
I want to write a simple script to make it easier to parse the iptables trace.
#!/bin/bash
tail /var/log/syslog -n $1 | cut -d" " -f8-10,12-13,20-22,31
filter:FORWARD:rule:6 IN=eth2 OUT=eth0 SRC=91.210.170.11 DST=10.200.2.2 PROTO=TCP SPT=40860 DPT=22 MARK=0x210014
filter:WWW_SERV_FILTER:rule:17 IN=eth2 OUT=eth0 SRC=91.210.170.11 DST=10.200.2.2 PROTO=TCP SPT=40860 DPT=22 MARK=0x210014
filter:FORWARD_ACCEPT:rule:1 IN=eth2 OUT=eth0 SRC=91.210.170.11 DST=10.200.2.2 PROTO=TCP SPT=40860 DPT=22 MARK=0x210014
raw:PREROUTING:policy:3 IN=eth2 OUT= SRC=91.210.170.11 DST=178.217.153.77 PROTO=TCP SPT=40860 DPT=10022
mangle:PREROUTING:rule:6 IN=eth2 OUT= SRC=91.210.170.11 DST=178.217.153.77 PROTO=TCP SPT=40860 DPT=10022
mangle:WWW_SERV:rule:1 IN=eth2 OUT= SRC=91.210.170.11 DST=178.217.153.77 PROTO=TCP SPT=40860 DPT=10022
mangle:WWW_SERV:rule:3 IN=eth2 OUT= SRC=91.210.170.11 DST=178.217.153.77 PROTO=TCP SPT=40860 DPT=10022
mangle:WWW_SERV:return:5 IN=eth2 OUT= SRC=91.210.170.11 DST=178.217.153.77 PROTO=TCP SPT=40860 DPT=10022
Answer the question
In order to leave comments, you need to log in
#!/bin/bash
tail /var/log/syslog -n $1 | cut -d" " -f8-10,12-13,20-22,31 | \
sed '
s/filter/\o33[32m&\o033[0m/g;
s/mangle/\o33[33m&\o033[0m/g;
s/raw/\o33[31m&\o033[0m/g;
s/nat/\o33[35m&\o033[0m/g;
s/OUT/\o033[1m&\o033[0m/g;.
s/IN/\o33[1m&\o033[0m/g;.
s/PROTO/\o33[1m&\o033[0m/g;.
s/MARK/\o33[1m&\o033[0m/g;.
s/DPT/\o33[1m&\o033[0m/g;.
s/SPT/\o33[1m&\o033[0m/'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question