evgu
evgu

Reputation: 25

How can I pass a file argument to my bash script twice and modify the filename

We have a large number of files in a directory which need to be processed by a program called process, which takes two aguments infile and outfile.

We want to name the outfile after infile and add a suffix. E.g. for processing a single file, we would do: process somefile123 somefile123-processed

How can we process all files at once from the command line? (This is in a bash command line)

Upvotes: 0

Views: 95

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

As @Cyrus says in the comments, the usual way to do that would be:

for f in *; do process "$f" "${f}-processed" & done

However, that may be undesirable and lead to a "thundering herd" of processes if you have thousands of files, so you might consider GNU Parallel which is:

  • more controllable,
  • can give you progress reports,
  • is easier to type

and by default runs one process per CPU core to keep them all busy. So, that would become:

parallel process {} {}-processed ::: *

Upvotes: 1

Related Questions