Re: Question about "find" and how to run "wc" & output to a file...

From: Frank Schmitt (frank.schmitt_at_4sc.com)
Date: 09/04/03


Date: 04 Sep 2003 18:05:34 +0200


"Robert Brookover" <robert.p.brookover@lmco.com> writes:

> Hi,
> OK, I have a command that I run from a script file, similar to the
> following:
>
> find /dir/subdir /anotherDir/anotherSubDir -type f -name "$1*" ! \(-name
> "*old*" \) -print > "$1.txt"
>
> This does *almost* what I want, which is to search through 2 specific
> directories for a file I type in from the command line, neglecting files w/
> the "old" extension (as in "myFile.cpp.old") & prints the results to a file
> named "MyFile.txt."
>
> Now, here's the kicker - I am searching for .h & .cpp files of the filename
> I type into the command line. I would *then* like for my script, once it
> finds "MyFile.cpp" and "MyFile.h" to also run the "wc" command on those 2
> files, to give me the line numbers for each, respectively.
>
> Then, in the output file ("MyFile.txt"), I would like it to be formatted
> like this (so I can then import it easily into Excel):
>
> MyFile
> MyFile.h /dir_where_it_lives 12 (this is the word count)
> MyFile.cpp /dir_where_it_lives 103 (this is the word count)
>
> Is this "do-able" easily, or is that going to be alot more scripting?

The following script should do the trick:

#!/bin/sh

# myfind.sh
# usage: myfind.sh <directory> <filename prefix>
# e.g. myfind /dir/subdir MyFile.txt

echo "$2"
for FILE in `find $1 -type f -name "$2*" | egrep -v ".old$"`
do
  SIZE=`wc -l $FILE | awk '{print $1;}'`
  DIRNAME=`dirname $FILE`
  BASENAME=`basename $FILE`
  echo "$DIRNAME $BASENAME $SIZE "
done

HTH & kind regards
frank

-- 
Frank Schmitt 
4SC AG		phone: +49 89 700763-0
		e-mail: frank DOT schmitt AT 4sc DOT com


Relevant Pages

  • Re: Multiple lines
    ... frank wrote: ... I am using a script file, so I broke up your command ...
    (comp.unix.shell)
  • Re: Word toolbars
    ... Once Frank answers those questions, can anyone else in the same versions ... I'm not the best person to ask, because I would not know what a toolbar ... Microsoft might have named the command or even what category it chose ... command to go to the next tracked change is called ...
    (microsoft.public.mac.office.word)
  • Re: Reflection and order of the fields
    ... My code needs to run on both ... are command objects that have different data fields depending on the nature ... Because of my specific serialization requirements, I was hoping to write my ... Frank D. Lombardo ...
    (microsoft.public.dotnet.framework)
  • Re: Reflection and order of the fields
    ... My code needs to run on both ... are command objects that have different data fields depending on the nature ... Because of my specific serialization requirements, I was hoping to write my ... Frank D. Lombardo ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Reflection and order of the fields
    ... My code needs to run on both ... are command objects that have different data fields depending on the nature ... Because of my specific serialization requirements, I was hoping to write my ... Frank D. Lombardo ...
    (microsoft.public.dotnet.general)