I have trying top back reference the first captured group in the below command:$ ls -lR | egrep 'd(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))---'drwxr-s--- 2 s9akhtar s9akhtar 4096 Feb 25 11:53 dir1dr-xrws--- 2 s9akhtar s9akhtar 4096 Feb 25 11:53 dir2dr-xrws--- 2 s9akhtar s9akhtar 4096 Feb 25 11:53 dir3drwxrws--- 2 s9akhtar s9akhtar 4096 Feb 25 11:53 dir4drwxrws--- 4 s9akhtar s9akhtar 4096 Feb 25 11:55 subdirdrwxrws--- 2 s9akhtar s9akhtar 4096 Feb 25 11:54 dir5drwxrws--- 2 s9akhtar s9akhtar 4096 Feb 25 11:54 dir6So I want to do something like this : ls -lR | egrep d(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))\1---but it comes up emptyHow come the back reference of the first captured group the big bracket not working: (rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s))
Egrep back referencing not working
grep;regular expression
If you want to repeat the pattern you need to use a count suffix of {2} instead of \1, which instead repeats the string the first pattern matched. Try:egrep '^d(rw(x|s)|rw-|r-(x|s)|-w(x|s)|r--|-w-|--(x|s)){2}---'which you can simplify to:egrep '^d(r[w-][xs-]|-w[xs-]|--[xs]){2}---'