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/servicesand now I get 'port/protocol'. Next, I try separate it with groups:~$ grep -E '\([0-9]{1,5}\)/(tcp|udp)' /etc/servicesand haven't any effect. Well, trying non extended grep:~$ grep '\([0-9]*\)/[tcp\|udp]\1' /etc/servicesbut results not right (/t or /u). So, how to use groups?
grep searching groups
grep;regular expression
You are referring to regex back-references.Please check these two references:https://stackoverflow.com/questions/4609949/what-does-1-in-sed-dohttp://www.gnu.org/software/grep/manual/html_node/Back_002dreferences-and-Subexpressions.htmlAnd see the output of grep '\([0-9]\)\1' /etc/services which will give you a resultset of lines where a digit is directly followed by the same digit (the back reference \1).