Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to run ./pythonScript keyword one time for each keyword in a text file, how can I do this from a gnome terminal? (without having to modify the pythonScript)

pseudo code:

for each keyword in file:
  ./pythonScript keyword
  waitfor(pythonScript to finish)
share|improve this question
up vote 1 down vote accepted

Assuming there is one keyword per line, here's a pure shell, portable solution:

while read -r line; do
    ./pythonScript "$line"
done <file

Here's a slightly simpler Linux solution:

<file xargs -d '\n' -n 1 ./pythonScript

Both solutions allow any character other than newline to appear in a keyword.

share|improve this answer

Is there a keyword per line from the file? If so,

while read keyword
    ./pythonScript $keyword
done < file
share|improve this answer
Yes the keywords are one per line (but some are phrases like "keyw1 and keyw2" in the same line), Would it still work? – ldabl Aug 14 '10 at 21:03

If you have GNU Parallel http:// installed you can do this:

cat file | parallel ./pythonScript

This will run the jobs in parallel can be very useful if you run on a multicore machine.

Watch the intro video for GNU Parallel to learn more:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.