On Sat, Aug 2, 2008 at 3:27 PM, Gora Mohanty <[EMAIL PROTECTED]> wrote:
> On Wed, 30 Jul 2008 13:56:43 +0530
> "Puneet Lakhina" <[EMAIL PROTECTED]> wrote:
>
>> On Wed, Jul 30, 2008 at 12:45, Gora Mohanty <[EMAIL PROTECTED]> wrote:
>>
>> > On Wed, 30 Jul 2008 12:32:13 +0530
>> > "Puneet Lakhina" <[EMAIL PROTECTED]> wrote:
>> >
>> > > you could use the following script
>> > > basedir=$1;
>> > > find $basedir -type d|sed "s#$basedir##g" | awk -F'/' '{print NF-1 "\n"}'
>> > |
>> > > sort -n | tail -1;
>> > >
>> > > invoke this using
>> > >  $>./script.sh <dir>
>> >
>> > [...]
>> >
>> > Try it with a directory named "My Documents".
>> >
>>
>> Yeah, sorry that wont work. Any workarounds? keeping in mind non
>> availability of printf.
> [...]
>
> Sorry, this had slipped into my "Reply Later" buffer. In a shell
> script, you have to quote any variable that might contain spaces.
> Thus,
>  basedir="$1"
>  find "$basedir" | sed "s#$basedir##g" | awk -F'/' '{print NF}' | sort -n | 
> tail -1
>
> However, if one is using gawk, or a modern awk, one can get it to replace
> sed (and, with some more work, probably sort, and tail also), viz.,
>  find "$1" | gawk -vbasedir="$1" -F/ '{gsub(basedir, "", $0); print NF-1}' | 
> sort -n | tail -1

Nice solution! Not strictly required for my current problem but good
to remember.. Much appreciated :)

-- Anupam

_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi 
http://www.mail-archive.com/[email protected]/

Reply via email to