I would like to grep ACCEPT, DROP, REJECT as is shown below.-P INPUT ACCEPT-P OUTPUT DROP-P FORWARD REJECTI executediptables -S | grep -E '\-P INPUT|\-P OUTPUT|\-P FORWARD' | awk '{print $2}'My output looks like thisINPUTOUTPUTFORWARDAnybody know how to grep only ACCEPT, DROP, REJECT? I just want grep policy in built-in chains. Below built-in chains I got user's chains which cannot be connected to result.Thank you,M
Grep expression with spaces - BASH
bash;grep
You were close. If you need the whole line:iptables -S | grep -- -P | grep -E ACCEPT|DROP|REJECTOutput-P INPUT ACCEPT-P OUTPUT DROP-P FORWARD REJECTIf you need only the matching words:iptables -S | grep -- -P | grep -oE ACCEPT|DROP|REJECTOutputACCEPTDROPREJECT