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
Trick to ignore space in folder name pulkit Shell Programming and Scripting 3 01-21-2008 08:07 AM
Looking for tips ant trick extend vi umen UNIX for Dummies Questions & Answers 0 03-25-2006 04:35 AM
I am stupid CoreyH UNIX for Dummies Questions & Answers 5 06-08-2001 04:27 PM
Really New and probably stupid... Dr_KillBlair UNIX for Dummies Questions & Answers 1 01-10-2001 01:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2002
criglerj's Avatar
criglerj criglerj is offline
Registered User
  
 

Join Date: May 2002
Location: Atlanta
Posts: 129
Question Stupid find trick

At work, we use a software development product (from a company that will remain nameless, but whose name may be considered a synonym for "logical"). The development trees are organized beneath a top directory, let's call it "$rat". The first level under $rat contains the major system names, and at that level there is either the list of subsystems or one additional directory layer then subsystems. I.e., using .1 for subsystems,
Code:
$rat
   skeletal
      protective.1
      support.1
      ambulatory.1
   circulatory
      blood
         redcells.1
         whitecells.1
         plasma.1
      endocrine.1
   dermal
      withhair.1
      withouthair.1
   muscular
      ambulatory.1
      manipulative.1
   sensory
      visual
         red.1
         green.1
         yellow.1
      olfactory.1
      ...
Beneath each subsystem, each there are copies of the views for each developer interested in developing there as well as the baselined views of the software. I.e., using .2 for the views,
Code:
$rat
   skeletal
      protective.1
         fred.2
         barney.2
         wilma.2
         baseline.2
      support.1
         fred.2
         barney.2
         betty.2
         baseline.2
         ...
So fred, barney and wilma do protective skeletal development, while fred, barney and betty do support skeletal development.

Here's the question: Is there a way to write a single "find" expression that will find, for every system, all the source code in betty's view, or (if betty doesn't have a view on the given code) all the source in the baseline view?

The best I've been able to come up with is a two level find:
Code:
find $rat -name '*.1' -prune -exec findbetty '{}' |
  while read viewname ; do 
    find $viewname -name '*.[ch]'
  done > output.txt
There are a few more clauses in both find commands to reject "logical's" tool-maintaintained directories.

findbetty is a script that does this:
Code:
#!/bin/sh
ls -a $1 |
  awk -v base=$1 '/betty\.2/    { print base "/" $0 ; found = 1 }
                  /baseline\.2/ { d = base "/" $0; }
                  END { if (!found && length(d)) print d }'
I.e., if in the given subsystem ".1" directory, there is a "betty.2", print it, otherwise if there is a "baseline.2", print that.

I'd like to be able to do this in a single "find" command with no calls to external programs.

Ideas?

Last edited by criglerj; 11-14-2002 at 05:18 PM..
  #2 (permalink)  
Old 11-17-2002
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
  
 

Join Date: Sep 2000
Location: Asia Pacific
Posts: 6,671
For more complex shell scripts, I suggest you use either PHP or PERL. You will have much more overall flexibility and capability. After using these more advanced shell, I rarely do anything in older shells anymore, except very simple scripts (and even the more simple scripts are fun in PHP and PERL).

Of interest, maybe:

www.hotscripts.com

  #3 (permalink)  
Old 11-18-2002
criglerj's Avatar
criglerj criglerj is offline
Registered User
  
 

Join Date: May 2002
Location: Atlanta
Posts: 129
Quote:
Originally posted by Neo
For more complex shell scripts, I suggest you use either PHP or PERL. You will have much more overall flexibility and capability. After using these more advanced shell, I rarely do anything in older shells anymore, except very simple scripts (and even the more simple scripts are fun in PHP and PERL).
Six months ago, I would have written this in Perl or Ruby. But if you look at the part that does the work, it's only 4 lines long --- 8 if you count the subservient ls/awk script --- which doesn't qualify as "more complex" in my mind. I guess I could use find2perl to prototype the Perl expressions I'm interested in, though ISTR you take about a 20% performance hit by going through Perl (not a big deal here).

FWIW, I save the output from this program, then from vi I execute another script that picks out the source file I want and prints its full path, as in
Code:
:e `findfile zzz.c`
It took me a while to understand what the vi intro doc meant when it said that arguments to ":e" are passed to the shell for expansion before trying to edit the file. But I think I've got it now ...
Closed Thread

Bookmarks

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 10:36 PM.


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