Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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
do
    ./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:// www.gnu.org/software/parallel/ 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: http://www.youtube.com/watch?v=OpaiGYxkSuQ

share|improve this answer

You must log in to answer this question.

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