Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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

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

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

Your Answer

 
discard

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.