2

I have a file which contains directories and subdirectories and I need to search for lines which are subdirectories. I used the grep command to perform the action but it does not work. Can you please let me know how to perform this action?

For example a file called a.txt has the below data:

.
./vou
./vou/bin
./vou/ctl
./vou2
./vou2/test

The end result should be:

./vou/bin
./vou/ctl
./vou2/test
  • Did you try grep '/.*/' a.txt? – Lambert Aug 26 '15 at 18:04
2

You can do it with egrep like

egrep "/[^/]+/" <file>

which will find a / then anything that is not a slash at least one time, then another /

Of course, this looks like the output of a find command, so you could instead just use the -mindepth 2 option like

find . -mindepth 2 -type d
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.