0

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)

3 Answers 3

1

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.

0
0

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

while read keyword
do
    ./pythonScript $keyword
done < file
1
  • 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, 2010 at 21:03
0

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

You must log in to answer this question.

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