Using the help switch (--help) on the route command gives the following output:
root@theapprentice:~# route --help
Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
route {-h|--help} [<AF>] Detailed usage syntax for specified AF.
route {-V|--version} Display version/author and exit.
-v, --verbose be verbose
-n, --numeric don't resolve names
-e, --extend display other/more information
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
<AF>=Use -4, -6, '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
I only want to retrieve the second line based on the word "add":
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
I don't want sed or awk.
I have tried using:
route --help |grep add
route --help |grep -o add
route --help |grep -E add
route --help |grep -E -o add
route --help |grep -E -o "add"
route --help |grep -E -o {add|del|flush}
route --help |grep -w {add|del|flush} <<<this one did not even work
sed
orawk
solution, but what about one done usinghead
?