Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 740827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:33:40+00:00 2026-05-14T08:33:40+00:00

I have a perl script (or any executable) E which will take a file

  • 0

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 -o`;
isdone=`ls *.txt | grep $PATTERN -o`;

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

#tack on the .xml prefix with sed or something

#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?

To clarify/extend the problem:

I have a bunch of programs that take input from sources like (but not necessarily) data/{branch}/special/{pattern}.xml and write output to another directory results/special/{branch}-{pattern}.txt (or data/{branch}/intermediate/{pattern}.dat, e.g.). I want to check in my jobfarming shell script if that file already exists.

So E transforms data/{branch}/special/{pattern}.xml->results/special/{branch}-{pattern}.dat, for instance. I want to look at each instance of the input and check if the output exists. One (admittedly simpler) way to do this is just to touch *.done files next to each input file and check for those results, but I’d rather not manage those, and sometimes the jobs terminate improperly so I wouldn’t want them marked done.

N.B. I don’t need to check concurrency yet or lock any files.

So a simple, clear way to solve the above problem (in pseudocode) might be

for i in `/bin/ls *.xml`
do
   replace xml suffix with txt
   if [that file exists]
      add to whatsleft list
   end
done

but I’m looking for something more general.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:33:41+00:00Added an answer on May 14, 2026 at 8:33 am
    #!/bin/sh
    
    shopt -s extglob # allow extended glob syntax, for matching the filenames
    
    LC_COLLATE=C     # use a sort order comm is happy with
    
    IFS=$'\n'        # so filenames can have spaces but not newlines
                     # (newlines don't work so well with comm anyhow;
                     # shame it doesn't have an option for null-separated
                     # input lines).
    
    files_todo=( **([A-Z])0[1-2][a-j]*.xml )
    files_done=( **([A-Z])0[1-2][a-j]*.txt )
    files_remaining=( \
      $(comm -23 --nocheck-order \
        <(printf "%s\n" "${files_todo[@]%.xml}") \
        <(printf "%s\n" "${files_done[@]%.txt}") ))
    
    echo jobserve E $(for f in "${files_remaining[@]%.xml}"; do printf "%s\n" "${f}.txt"; done)
    

    This assumes that you want a single jobserve E call with all the remaining files as arguments; it’s rather unclear from the specification if such is the case.

    Note the use of extended globs rather than parsing ls, which is considered very poor practice.

    To transform input to output names without using anything other than shell builtins, consider the following:

    if [[ $in_name =~ data/([^/]+)/special/([^/]+).xml ]] ; then
      out_name=results/special/${BASH_REMATCH[1]}-${BASH_REMATCH[2]}.dat
    else
      : # ...handle here the fact that you have a noncompliant name...
    fi
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 369k
  • Answers 369k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You must add the movie view to an existing view… May 14, 2026 at 6:25 pm
  • Editorial Team
    Editorial Team added an answer The name of the clicked button ends up in params:… May 14, 2026 at 6:25 pm
  • Editorial Team
    Editorial Team added an answer Instead of int *funPtr1(int, int) you need int (*funPtr1)(int, int)… May 14, 2026 at 6:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.