How to define two digits variable in shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to define two digits variable in shell script?
# 1  
Old 12-03-2015
How to define two digits variable in shell script?

Dear Shell script Experts,
I am working on shell script which is defined here, qsub_seq.csh [1]. The purpose of this script is to read few input files (with defined starting index and last index) and make processing faster over server.
For some task, I had 1064 of input files, so I wrote another script, submitjob.sh [2] to make it quicker.
However, instantly I realized that it failed to work as the qsub_seq.csh script read the first digit of the input file and delete them all, though my input files have range from 0 till 1064, as given some examples of input files [3].

Any help, how to make qsub_seq.csh read two digits variable?

thank you in advance,
emily

Code:
[1] qsub_seq.csh
#!/bin/csh                                                                                                                                                                                                      
# $1 - code name                                                                                                                                                                                                
# $2 - analysis macro                                                                                                                                                                                           
# $3 - base directory                                                                                                                                                                                           
                                                                                                                                                            
# $4 - sample name                                                                                                                                                                                              
# $5 - starting index                                                                                                                                                                                           
# $6 - last index                                                                                                                                                                                               

rm -rf $4_files
mkdir $4_files
cp $2 $4_files/
cp qsub.sh $4_files/
cp temp $4_files/
cd $4_files
set n = $5
while ( $n <= $6 )
    ls $3/$4/$4_${n}*.root > $4_$2_$n
    ./qsub.sh $1 $2 $4_$2_$n
    @ n++
end
cd ../

Code:
[2] submitjobs.sh
#!/bin/sh                                                                                                                                                                                                       

Start=0
Step=9
Entries=1164

while [ $Start -lt $Entries ]
do
   if [ $Start -ge $Entries ]
   then
      break
   fi

   End=`expr $Start + $Step - 1`

   ./qsub_seq.csh AnalysisMacro analysisMacro.conf /nfs/dust/ DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8 $Start $End
   echo 'job submitted for ' $Start, $End
   Start=`expr $Start + $Step`
done


Code:
[3] 
--------------
/nfs/dust/emily/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_0.root
/nfs/dust/emily/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_151.root
/nfs/dust/emily/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_299.root
/nfs/dust/emily/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_2.root
/nfs/dust/emily/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_99.root
/nfs/dust/emily/DYJetsToLL_M-50_TuneCUETP8M1_13TeV-amcatnloFXFX-pythia8_9.root

# 2  
Old 12-03-2015
sorry for offtopic, but - Top Ten Reasons not to use C Shell
# 3  
Old 12-03-2015
From top to down:

submitjobs.sh
1) This part is not required:
Code:
if [ $Start -ge $Entries ]
   then
      break
   fi

As long it is lesser (-lt) it cannot exceed equal or greater than STOP, and will therefor break anyway.
2) Why not make STEP = 8, rather than END = START + STEP (9) - 1
3) I'm not familiar (enough) with cshell, but what happens in: ./qsub.sh $1 $2 $4_$2_$n
4) (one could write functions instead of different files)
5) You do overwrite the START variable before the loop ends, is that intended?

Last but not least, try to execute your scripts verbose / in debug mode, to see where the issues are, and how they look like:
Code:
 sh -x submitjobs.sh

And within ./qsub_seq.csh, change the shebang to #!/bin/csh -x (if that option is available for csh?)

hth

Last edited by sea; 12-03-2015 at 11:24 AM.. Reason: changed code
# 4  
Old 12-04-2015
Actually, I can't see how and where
Quote:
Originally Posted by emily
qsub_seq.csh script read the first digit of the input file
. Possibly when passing parameters?
Wouldn't it make sense to collect the entire task into one single (sh-, bash-, ksh-) script?
# 5  
Old 12-04-2015
I see a problematic
Code:
  ls $3/$4/$4_${n}*.root > $4_$2_$nby

Perhaps you can simply omit the *?
# 6  
Old 12-15-2015
Hello all,
Thanks for your replies, it helped me to dig it further.
Now, I realize I shall be able to fix it, if I could figure out how to provide the command line in a shell script to create directory/anotherDirectory. Any hints are appreciated..
Basically, I want to do somethiing like this :
Code:
#!/bin/sh                                                                                                                                                                                                       

Start=0
Step=9
Entries=1164

./qsub_seq.csh  file.conf /inifitla/input/file/location Directory/subDir$Start 0 2

Basically, I want to redirect the output to '
Code:
Directory/subDir$Start

' which I have to create.

Greetings,
emily
# 7  
Old 12-15-2015
man mkdir ?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

sed / awk script to delete the two digits from first 3 digits

Hi All , I am having an input file as stated below 5728 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r03_q_reg_20_/Q 011 611 U_TOP_LOGIC/U_CM0P/core/u_cortexm0plus/u_top/u_sys/u_core/r04_q_reg_20_/Q 011 3486... (4 Replies)
Discussion started by: kshitij
4 Replies

2. Shell Programming and Scripting

How to define a variable in a BASH script by using a JSON file online?

Hello, I would like to modify an existing script of mine that uses a manually defined "MCVERSION" variable and make it define that variable instead based on this JSON file stored online: https://s3.amazonaws.com/Minecraft.Download/versions/versions.json Within that JSON, I 'm looking for... (4 Replies)
Discussion started by: nbsparks
4 Replies

3. Shell Programming and Scripting

Define variable from file.

HI I have file A.txt _1A _2A _3A _4A I want define all as different variable. $1A=_1A $2B=_2A $3C=_3A $4D=_4A Now i can use any variable in my script. (3 Replies)
Discussion started by: pareshkp
3 Replies

4. Shell Programming and Scripting

question about define variable.

Hi, Unix Gurus, In our existing file, there is a script like #!/bin/sh step=${1:-0} cur_step=10 if ... My question is what's "${1:-0}" mean? I know it defines a variable but I don't know what's (1:-0) mean? :wall: Thanks in advance. (2 Replies)
Discussion started by: ken002
2 Replies

5. Shell Programming and Scripting

Get the places of binary digits in the korn shell script

TO THE ALMIGHTY FORUM , though i have already posted the same question on hex to binary thread , i am posting here also for other beginners who may benefit from this thread... I have a 32 bit binary containing a series of 1' and 0's , and i am stuck... (2 Replies)
Discussion started by: venu
2 Replies

6. Shell Programming and Scripting

bash - define a variable

Hello, I would like to define a variable based on another variable: a=5 b$a=100 This does not work. What is the right way to do it? Thanks ---------- Post updated at 07:37 PM ---------- Previous update was at 07:33 PM ---------- Found my answer with the search function (did not... (0 Replies)
Discussion started by: jolecanard
0 Replies

7. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

8. UNIX for Dummies Questions & Answers

define length of variable

I have a variable with a value of "05". When I add one to that variable, using the command: CURR_YY=`expr $CURR_YY + 1`, I get the value of "6", losing the leading zero (which is needed for passing to another script). How do I keep the leading zero? Thank you! (10 Replies)
Discussion started by: cbarker
10 Replies

9. UNIX for Dummies Questions & Answers

Using Grep to Define a Variable

I am using korn shell unix. I have a script that I am working with to do a check for me using a text file. #finds "Time" from the text file and cuts the second field from the #line A= grep Time test.txt | cut -f2 # the "#Missing" is being pulled from the second field of the text... (1 Reply)
Discussion started by: cspcspcsp
1 Replies
Login or Register to Ask a Question

Featured Tech Videos