[LUGSB] David: I need some help on using xargs command
Dan Kegel
dank at kegel.com
Wed Nov 17 00:05:16 EST 2010
Vacheh David Sardarian <vsardari at ic.sunysb.edu> wrote:
> I'm stuck and I was wondering if there's anyone that could help me? Here is
> the problem.... I have 35 to 50 files in each folder that I have to process
> using the python script that I wrote. The python script when executes... it
> asks for a file name to be entered. For example, name.txt and it takes the
> file "name.txt" and it does something with it and it outputs name_size.txt.
> The thing is that I have around 35-50 .txt files... and i don't feel like
> copy and pasting 35-50 times every time I execute my python script.
First off, why not write the python script to take a list of filenames?
Then you could do
foo.py *.txt
and it would do them all.
But if you want to use xargs, you might try
find . -name '*.txt' | xargs foo.py
Since foo.py only takes one argument, you might need to use -n 1, e.g.
find . -name '*.txt' | xargs -n 1 foo.py
And if you don't want to run it on its output from previous runs,
filter out the output files with
find . -name '*.txt' | grep -v _size.txt | xargs -n 1 foo.py
Does that help?
- Dan
More information about the lugsb
mailing list