Script to Find Lookups to Files
Lerebours, Jose
Jose.Lerebours at EagleGL.com
Tue Mar 29 04:06:28 PST 2005
Brian posted:
>
> > Since I've gotta task of renaming filePro files to get rid
> of dots in the
> > names, I recall there once was a script that someone
> provided here that
> > would show you all of the lookups that a particular file
> made, or had made
> > to it (?).
> >
> > This kinda script would make my task sooooooo much easier
> to do. Was it
> > Stockler's Utilities thingamabob?
>
> I and probably others have probably posted little one or
> two-liner shell
> commands to do it. There is more than one way.
>
> Here is a quick-n-dirty, but it'll just fail if the total
> number of files is
> too large.
> It looks for all lines with lookup and . in the then section.
>
> cd /u/appl/filepro
> egrep -n '.*:.*:lookup .*\..*' */prc.* |less -S
>
> This handles unlimited number of files:
> cd /u/appl/filepro
> find ./ -name 'prc.*' |xargs egrep -n '.*:.*:lookup .*\..*' |less -S
>
> or |pg if you don't have less, but this less syntax will not
> wrap the long
> lines, making it a little easier to read
>
> Here is an awk-based way that does the same as above.
>
> cd /u/appl/filepro
> find ./ -name 'prc.*' |xargs -n1 awk -F: '{if($3 ~ "lookup"
> && $3 ~ ".")
> print ARGV[1]": "NR": "$3}' |less -S
>
> the output is:
> filename: line number:"then" section of the line
>
> The advantage here is that you can add code to the awk script
> to get more
> and more accurate filtering and even perform actions on a per
> line and per
> file basis.
> For example you could add some more if() statements to
> recognize and ignore
> comments, recognize and ignore browse formats, recognize
> lookups where the
> target is a variable and include them rather than ignore them
> so you can go
> look at the processing and figure out if those variables
> would contain a dot
> at run-time yourself.
> It could even write out an edited copy of the process table where the
> lookups have all been changed from dots to underscores and
> even run system()
> with B. Stocklers cabe script to compile the new tok.
> It can get more and more fancy depending on if it's worth the
> bother, which
> depends on just how many files you have and just how many
> substitutions you
> have to do.
> The more files and the more broken lookups, the more it's
> worth getting a
> sophisticated script to do more of the work automatically.
>
> Think of awk script like rreport processing. It has
> equivalents for @once,
> @done, a system() command, and the main body runs once for
> each record,
> etc...
>
Simple tools one should have in his toolbox. These simple scripts
(or commands) are things of beauty.
Regards;
Jose Lerebours
More information about the Filepro-list
mailing list