Getting all the subdirectories inside directories in excel file

Can anyone help me with a short command or script for the below scenario

there is a path,

/a/b/c/home??

Inside the above path there are number of subdirectories such as

one
two
three
four

i need to take all the subdirectories inside

home??

with full path. i need only one level of subdirectories.
the output should be.

/a/b/c/homeaa/one
/a/b/c/homeaa/two
/a/b/c/homeaa/three
/a/b/c/homeaa/four
/a/b/c/homebb/one
/a/b/c/homebb/two
/a/b/c/homebb/three
/a/b/c/homebb/four

Is there a way so that i can get the above output in an excel file?

If you don't mind having a trailing backslash printed with your directory names, the trivial way to do it is:

printf '%s\n' /a/b/c/home??/*/

If you do mind the trailing backslash, you can use a for loop on the same pathname pattern and print the loop control variable with the backslash stripped off.

Of course, how you put the results into an excel spreadsheet is up to you.

1 Like

Hello little,

Nice to see you again in forum. Could you please try following and let me know if this helps, I have made a similar directory structure in my /tmp and tried following command, you can replace the path with your actual and path and if happy with results then re-direct it's output to an excel file too.

find /tmp/a/b/c/home?? -mindepth 1 -maxdepth 1 -type d | sort -t/ -k5,5

In my case following is the output.

/tmp/a/b/c/homeaa/one
/tmp/a/b/c/homeaa/three
/tmp/a/b/c/homeaa/two
/tmp/a/b/c/homebb/one
/tmp/a/b/c/homebb/three
/tmp/a/b/c/homebb/two

Hope this helps.

Thanks,
R. Singh

1 Like

Hi Ravinder, thanks for the code, I tried your code, I know its a correct one but ksh shell is not able to recognize maxdepth and mindepth options of find command.

Unless your version of the Korn shell has find as a built-in, the issue isn't ksh , but the version of find you're using. And, since you didn't bother telling us what operating system you're using, RavinderSingh13 supplied a sample script that works on the system he's using without worrying about options that might not be available on your unnamed system.

The code I suggested should work with ksh on any system (unless you have a huge number of matching directories and/or relatively long pathnames). And, if that is a problem in your environment, it would disappear if you used the for loop I suggested.