The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help needed nnayagam Shell Programming and Scripting 2 03-07-2008 03:34 AM
Little help needed. Netghost AIX 5 08-10-2006 11:29 AM
Help needed dsravan Shell Programming and Scripting 2 07-20-2006 06:37 AM
awk help needed. cskumar Shell Programming and Scripting 0 07-20-2006 04:24 AM
Sed help needed stevefox Shell Programming and Scripting 5 12-04-2005 10:44 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-28-2005
Registered User
 

Join Date: May 2005
Posts: 2
Help is needed

Hi
I'm trying to print a directories struct tree that will look like this:
A
_a
_b
_B
__c
__d
__C
___e
B
_a
_b

I'm doing a recursion, but how can I know how much space is needed before printing after the recursion?
Reply With Quote
Forum Sponsor
  #2  
Old 12-28-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
attached is a 'tree walker'.

find . | nawk -f tree.txt

try it.
Attached Files
File Type: txt tree.txt (1.7 KB, 19 views)

Last edited by vgersh99; 12-28-2005 at 02:59 PM.
Reply With Quote
  #3  
Old 12-29-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
one more,

try this

Code:
# !/usr/bin/ksh

nestlevel=0
displaychar="__"
path=""

if [ $# -eq 0 ]
then
startdir=.
else
startdir="./"$1
fi

display()
{
app=""
temp=$nestlevel
while [ $temp -gt 0 ]
do
app=$app$displaychar
temp=$(($temp - 1))
done
echo $app$1
}

subdir()
{
path=$1
for subdir in `ls -l $1 | grep ^d | awk '{print $9}' 2>/dev/null`
do
display `basename $subdir`
nestlevel=$(($nestlevel + 1))
path=$path"/"$subdir
subdir $path
path=`echo $path | sed -e "s/\/'$subdir'//"`
done
nestlevel=$(($nestlevel - 1))
}

#Shoot here
for dir in `ls -l $startdir | grep ^d | awk '{print $9}' 2>/dev/null`
do
display `basename $dir`
nestlevel=$(($nestlevel + 1))
subdir $startdir"/"$dir
done

exit 0
Reply With Quote
  #4  
Old 12-30-2005
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
here is one more and a much simpler one

Code:
# !/usr/bin/ksh

app=""
displaychar="__"
for var in `find . -name '*' -ls | awk '$3 ~ /^d/ { print $11}' | sed -e 's/.\///'`
do
finaldir=`echo $var | sed -e 's/^[a-zA-Z0-9].*\///'`
nestlevel=`echo $var | sed -e 's/[a-zA-Z0-9]//g' | wc -c`
nestlevel=$(($nestlevel - 1))
while [ $nestlevel -gt 0 ]
do
app=$app$displaychar
nestlevel=$(($nestlevel - 1))
done
echo $app$finaldir
app=""
done

exit 0
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0