shell script segment to avoid overwriting files

Posted by johndashen on Stack Overflow See other posts from Stack Overflow or by johndashen
Published on 2010-04-16T23:09:52Z Indexed on 2010/04/16 23:13 UTC
Read the original article Hit count: 186

Filed under:
|
|
|
|

I have a perl script (or any executable) E which will take a file foo.xml and write a file foo.txt. I use a Beowulf cluster to run E for a large number of XML files, but I'd like to write a simple job server script in shell (bash) which doesn't overwrite existing txt files.

I'm currently doing something like

#!/bin/sh
PATTERN="[A-Z]*0[1-2][a-j]"; # this matches foo in all cases 
todo=`ls *.xml | grep $PATTERN`;
isdone=`ls *.foo | grep $PATTERN`;

whatsleft=todo - isdone; # what's the unix magic?

#and then call the job server; 
jobserve E "$whatsleft";

and then I don't know how to get the difference between $todo and $isdone. I'd prefer using sort/uniq to something like a for loop with grep inside, but I'm not sure how to do it (pipes? temporary files?) As a bonus question, is there a way to do lookahead search in bash grep?

© Stack Overflow or respective owner

Related posts about shell

Related posts about scripting