0

I have a large number of .pbs files that I want to submit to a remote cluster. I want to be able to name the .pbs file something like "param1_123_param2_45.pbs", and then feed them into the ARGS for a Julia code. Below is an example .pbs of what I'm trying to do:

1 #!/bin/tcsh 
2 #PBS -l mem=10gb,nodes=1:ppn=2,walltime=1:00:00
3 #PBS -j oe
4 #PBS -o ./log/julia.${PBS_JOBID}.out
5 #PBS -t 1-3
6 
7 module load julia/1.5.1 python/3.8.1
8 
9 cd path/to/file  
10 
11 julia Example.jl 123 45

Except 123 & 45 are replaced by some general terms given in the name of the .pbs file. Is there an easy way to do this?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Joshuah Heath
  • 663
  • 1
  • 5
  • 20

1 Answers1

1

You can use AWK. For example, content of file param1_123_param2_45.pbs:

PARAM1=$( echo ${0%%.pbs} | awk -F "_" '{print $2}' )
PARAM2=$( echo ${0%%.pbs} | awk -F "_" '{print $4}' )
echo "Filename: $0"
echo "Param 1: $PARAM1"
echo "Param 2: $PARAM2"

Running: bash param1_123_param2_45.pbs

Output:

Filename: param1_123_param2_45.pbs
Param 1: 123
Param 2: 45
Andriy Makukha
  • 7,580
  • 1
  • 38
  • 49
  • Thank you; this solves the main problem I was having. However, I get a bizarre error when I submit to the cluster; you can see my error here: https://stackoverflow.com/questions/65755537/using-parameters-from-file-name-as-arguments-for-julia-script-on-cluster If you had any additional insight, I'd greatly appreciate it. – Joshuah Heath Jan 16 '21 at 22:57