Re: Grep / Bash problem

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?

thanks again

<conrads@xxxxxxxxxxxxxxxx> wrote:

> Your script could be much more simply written as:
> while read
> do
> MATCH=`grep -c "$REPLY.*" num3
> if [ $MATCH -gt 1 ]
> then
> ... (omitted for clarity's sake)
> fi
> 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"

Relevant Pages

  • Sol8 and EVA hangs
    ... Secure Path 3.0D is loaded for channel failover. ... retrying command ... # Adapter hard loop ID address to use on the fibre channel bus. ...
  • Summary: Sol8 and EVA hangs
    ... Oct 8 11:00:41 proddb SCSI transport failed: reason 'aborted': ... retrying command ... # Adapter hard loop ID address to use on the fibre channel bus. ... # before reporting I/O errors. ...
  • Re: Using foreach loop to create radiobutton menu
    ... Your foreach loop is not the problem, the problem is how you define the -command. ... The only possible thing the interpreter can do is substitute the current value of range, which is likely the last value once your loop exited. ... One choice is double quotes. ... The double quotes means that $range gets expanded while in the loop, long before the puts command actually runs. ...
  • Re: Grep / Bash problem
    ... num3 is a list to make sub-directories ... LINES sets the number of loop ... Grep will not read the fixed string pattern correctly from ... >(other than the lines with brackets). ...
  • Re: Issue implementing Runtime.exec() with StreamGobbler
    ... So jloader basically calls (starts the loop) ... As you can see the last line, the New Command Executer never returned. ... If your test driver is hanging, I'd guess that the test process itself is ...