Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
2 edited tags
| link
source | link

grep searching groups

I'm trying to learn to use grep groups, like sed \1\2\3, but have a problem. For example I filtering /etc/services file to separate all ports. What I do:

~$ grep -E '[0-9]{1,5}/(tcp|udp)' /etc/services

and now I get 'port/protocol'. Next, I try separate it with groups:

~$ grep -E '\([0-9]{1,5}\)/(tcp|udp)' /etc/services

and haven't any effect. Well, trying non extended grep:

~$ grep '\([0-9]*\)/[tcp\|udp]\1' /etc/services

but results not right (/t or /u). So, how to use groups?