Need help understanding this Regex.

Hi everyone,

This regex looks simple and yet it doesn't make sense how it's manipulating the output.

ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:0c:49:c2:35:6v
          inet addr:192.16.1.1  Bcast:192.168.226.255  Mask:255.255.255.0
          inet6 addr: fe82::40c:29ff:fec4:3b68/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1544342 errors:0 dropped:0 overruns:0 frame:0
          TX packets:137833 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:119084975 (119.0 MB)  TX bytes:51011004 (51.0 MB)
          Interrupt:19 Base address:0x2000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

output:

ifconfig -a | egrep '^[^\t ]'
eth0      Link encap:Ethernet  HWaddr 00:0c:29:c6:3b:68
lo        Link encap:Local Loopback

The way i am reading this..

Match at the beginning of the line ^, everything except tab and space??!

With the understanding that this depends on your shell and O/S...

'^[^\t ]' will match any line that does not being with a space, a "t" or "\".

If you want to match anything that does not being with whitepace, use '^[^[:space:]]' . If you want to limit this to a space or tab use $'^[^\t ]' .

To add, an (shell independent) alternative to limit it to space and tab is to use '^[^[:blank:]]'