0

In order to submit array jobs using Slurm, I've renamed hundreds of files with incremental numbers using the following command:

COUNT=1
for file in ./*; do
    mv "$file" "${COUNT}"
    let COUNT++
done

The original file names contain a mix of alphabet, numbers and special characters.

  1. How do I restore the name of the output files (which are incremental numbers) back to their original file names (mix of alphabet, numbers and special characters)? There are matched IDs in their first columns. And there shouldn't be an issue of matching to wrong files because the IDs are unique among the original files.

example of an original file

    $ cat NA0457:3411.txt
    ABC1234 789326-26-1
    DEF4321 84201-058-0
    GHI1234 3789167469-

example of an input file (renamed to 1)

    $ cat INPUT_DIR/1
    ABC1234 789326-26-1
    DEF4321 84201-058-0
    GHI1234 3789167469-

example of the output file

    $ cat OUTPUT_DIR/1
    DEF4321 842010580
    DEF4321 --------- 
    GHI1234 3789167469
    GHI1234 ----------
    ABC1234 789326261
    ABC1234 ---------

example of the desired output file (renamed to NA0457:3411.out)

    $ cat OUTPUT_DIR/NA0457:3411.out
    DEF4321 842010580
    DEF4321 --------- 
    GHI1234 3789167469
    GHI1234 ----------
    ABC1234 789326261
    ABC1234 ---------
  1. Also, I don't understand the basis of renaming using the command above because the files are not renamed in numbers according the order the original file names.
  • I don't see a possibility to make the rename reverse. Nowhere in your files is the original filename saved, it can't be reconstructed based on the information in your question. How is that "mix of alphabet, numbers and special characters" generated? – chaos Sep 30 '15 at 7:37
  • Thanks! I've slowly figured out how the above script works and therefore can create a text file containing both the old and new names. I'm currently trying to revert the names back based on the text file. Will report a brief answer soon. – ahelix Sep 30 '15 at 7:49
  • If you post an example of that text file, I'm sure you will get an answer – chaos Sep 30 '15 at 7:51
  • Got it! I've followed the answers of below thread. Is there a way to make this question resolved? stackoverflow.com/questions/24071114/… – ahelix Sep 30 '15 at 8:56
  • 1
    there's nothing about sbatch -a that limits it to only accepting filenames with numbers. If your batch script does that, then that's a design decision that you made when writing your script. a design decision that, as i said before, should be re-visited. and if you really want to use $SLURM_ARRAY_TASK_ID directly, you don't have to replace the entire filename with a number, you could just append a number to the filename, e.g. mv "$file" "$file.$COUNT" - that way you won't be tossing away the original filename – cas Oct 1 '15 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.