Re: Grep / Bash problem
- From: Elmer Fudd <efudd@xxxxxx>
- Date: Sun, 29 Jan 2006 00:43:58 -0500
Thanks for the input. I realize my sample loop must look kludgey to a
pro, but I've done very little programming since college (and to give
you a clue how long that's been, it was FORTRAN with punchcards;
infinite loops in my batch files output were probably responsible for
many dead trees back in the day). I now have some basic admin needs and
am trying to avoid diving in too deep. (Unix has a way of sucking me in
though...) OTOH, my fat script _did_ actually run. It's the "twiddling
and tweaking" part I need help with!
I'm still finding out about bash's built-in variables; I will learn
more about the read command and $REPLY so I understand this better.
Since the read command uses the < input, does num3 still need to be
explicitly named in the actual grep line?
> Your script could be much more simply written as:
> while read
> MATCH=`grep -c "$REPLY.*" num3
> if [ $MATCH -gt 1 ]
> ... (omitted for clarity's sake)
> done < num3
> Instead of using $VAR1, you take advantage of bash's $REPLY variable, which
> will contain the entire line obtained by the read command. This also
> eliminates the need to do a "wc -l", to repeatedly "cat" the same file, and
> to increment and compare a loop index variable. Your first four lines
> become completely unnecessary.
> As you can see above, the MATCH= assigment can also be simplifiled by using
> the -c switch to grep, which returns the count of matches.
> As for the problem with brackets in filenames, that will require a bit more
> twiddling and tweaking. I'll leave that as an exercise for you. :-)
> Conrad J. Sabatier <conrads@xxxxxxx> -- "In Unix veritas"
- Prev by Date: Writing a unix command prompt
- Next by Date: Writing a unix command prompt
- Previous by thread: Re: Grep / Bash problem
- Next by thread: Re: Grep / Bash problem