1

I have a large number of scripts that can be run as separate jobs on a computing cluster, which uses slurm. I want to select some of them, based on the contents, to submit. It's easy to identify the filenames of the jobs I want using grep, but I'm struggling to pipe those and submit them.

I thought that I could do something like this:

grep -l 'regex' script_folder/* | xargs sbatch

However, this appears to submit the all the scripts as one job, when I want each script to be its own separate job.

4
  • grep will look at the contents of files, not at filenames. Do you want to submit based on filenames or file contents?
    – Kusalananda
    Apr 14, 2017 at 17:46
  • @Kusalananda I'm selecting based on the file contents, but the -l flag makes grep return the filenames.
    – njc
    Apr 14, 2017 at 17:48
  • I was momentarily confused by the bit saying "identify the filenames".
    – Kusalananda
    Apr 14, 2017 at 17:59
  • @Kusalananda Makes sense; it was somewhat unclear.
    – njc
    Apr 14, 2017 at 18:05

1 Answer 1

3
grep -l 'pattern' script_folder/* | xargs -n 1 sbatch

xargs will by default read as much as can fit on one command line before executing the given utility with all the things that it has read.

With -n 1 you limit the number of items that it passes to the utility to a single item per invocation.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .