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
- Next message: Marc Rochkind: "Re: Suggestions on how to handle this more efficiently"
- Previous message: Materialised: "Suggestions on how to handle this more efficiently"
- In reply to: Robert Brookover: "Question about "find" and how to run "wc" & output to a file..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Marc Rochkind: "Re: Suggestions on how to handle this more efficiently"
- Previous message: Materialised: "Suggestions on how to handle this more efficiently"
- In reply to: Robert Brookover: "Question about "find" and how to run "wc" & output to a file..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|