0

I'm working with a simple function that outputs some useful information about jobs I run on a cluster. It's called report:

function report()
{
   for FILE in $*;
      do tac $FILE | grep best -m1;
   done;
}

I want to call report on the output files I generate, but only when something goes wrong and the job is terminated. The output file will have Terminated as the last line. So, for instance:

[XXXXXX@login-0-0 scripts]$ grep Term optim_HGF.o1910512 -n
242:Terminated

[XXXXXX@login-0-0 scripts]$ report optim_HGF.o1910512
New best fit at function call 4496.  Took 6.292452e+00 seconds. Objective = 4.129260e-01 

Now I try to use grep to find the files for which something went wrong and pipe the names to report.

[XXXXXX@login-0-0 scripts]$ grep optim_HGF.o* -l | report

But this gives no output. How can I accomplish what I'm aiming to do?

Sevenless
  • 2,805
  • 4
  • 28
  • 47

1 Answers1

2

The command you're missing is xargs:

grep -l Term optim_HGF.o* | xargs report
C2H5OH
  • 5,452
  • 2
  • 27
  • 39
  • 1
    One catch though, report here is an aliased function and not a command, so the subshell that xargs generates is unaware of it. Your answer put me on the track to this answer: http://stackoverflow.com/questions/513611/xargs-doesnt-recognize-bash-aliases that ended up meeting my needs. Thanks! – Sevenless Apr 06 '12 at 01:04