The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Protecting the directory tree rooneyl UNIX for Dummies Questions & Answers 2 02-17-2008 05:59 PM
Searching directory tree blane Shell Programming and Scripting 7 05-29-2007 07:30 PM
directory as tree anything2 High Level Programming 2 03-01-2007 09:38 AM
Space Used by Directory Tree johnk99 Filesystems, Disks and Memory 1 07-22-2002 12:30 PM
Directory tree search??? solvman High Level Programming 3 09-28-2001 01:27 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-24-2008
ravi raj kumar ravi raj kumar is offline
Registered User
  
 

Join Date: Dec 2006
Location: hyderabad
Posts: 102
directory tree

Hi all,
The following is a script for displaying directory tree.

D=${1:-`pwd`}
(cd $D; pwd)
find $D -type d -print | sort |
sed -e "s,^$D,,"\
-e "/^$/d"\
-e "s,[^/]*/\([^/]*\)$,\:-----\1,"\
-e "s,[^/]*/,: ,g" | more
exit 0

I am trying to understand the above script.But i am not able to understand the following 2 lines

-e "s,[^/]*/\([^/]*\)$,\:-----\1,"\
-e "s,[^/]*/,: ,g" | more

can any body pls tell me how the above two lines works.

cheers
RRK
  #2 (permalink)  
Old 01-24-2008
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
these are sed syntex of find and replace...with regular expressions..
in first line- its searching for "/" in the begining of line for any occurance of "/". [ shown by "*"] escaped paranthesis are used to tell how many occurance.. $ used to find @ the end of every line.. \1,\2 etc used to tell where to find...
  #3 (permalink)  
Old 01-24-2008
anchal_khare anchal_khare is offline
Registered User
  
 

Join Date: Jun 2007
Location: Mumbai,India
Posts: 325
1 more thing.. [^/] means not to find "/". "^" is used to tell in the start of the line...
and if "^" used inside [] thn it treats as the negation of the exression followed by "^".

hope its clear.
  #4 (permalink)  
Old 01-24-2008
Klashxx's Avatar
Klashxx Klashxx is offline Forum Advisor  
HP-UX/Linux/Oracle
  
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 393
I did an awk tree sometime ago, maybe could be usefull for you:
Code:
find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5  && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}'  FS='/'

Last edited by Klashxx; 01-25-2008 at 09:52 AM.. Reason: one liner optimization
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0