Help parsing job script input parameters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help parsing job script input parameters
# 1  
Old 01-15-2011
Help parsing job script input parameters

I have a job script that runs with input parms from the command line.
Code:
job.sh -p parm1_parm2_parm3_parm4_file_1.dat

The parms are separated by _

The last parm is a file name and can have an _ in the name.

I currently use the following commands to extract the parms
Code:
parm1=`eval echo \$JOBPARM|awk -F_ '{print $1}'`
parm2=`eval echo \$JOBPARM|awk -F_ '{print $2}'`
parm3=`eval echo \$JOBPARM|awk -F_ '{print $3}'`
parm4=`eval echo \$JOBPARM|awk -F_ '{print $4}'`

How do I get the 5th parm and include the _, if one exists, so that

parm5 = file_1.dat.

thanks

Last edited by Scott; 01-15-2011 at 01:55 PM.. Reason: Code tags, please...
# 2  
Old 01-15-2011
try if the below helps

Code:
echo "parm1_parm2_parm3_parm4_file" | awk -F"_" '{ if($6 != "") print $5"_"$6; else print $5}'

Code:
echo "parm1_parm2_parm3_parm4_file_1.dat" | awk -F"_" '{ if($6 != "") print $5"_"$6; else print $5}'

# 3  
Old 01-15-2011
Worked awesome.
Thanks so much
# 4  
Old 01-15-2011
you are welcome Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Safely parsing parameters

I have a string like root=/dev/sda3 noacpi foo "Baz mumble" which I would like to separate into tokens like a shell does. This would be easily done with eval but that would open a security hole big enough to drop a cow through, injecting arbitrary code would be easy as pie. How can I parse this... (15 Replies)
Discussion started by: Corona688
15 Replies

2. Programming

Value changed when parsing parameters

I get a strange problem here, and ask for help. (gdb) 28 set_file_bit( file, bytePos, bitPos, argv ); (gdb) p argv $3 = 0xbfffef5c "00" (gdb) s set_file_bit (file=0x804b008, bytePos=2, bitPos=2, binary=0x80490e5 "11") at util/file.c:112 ... (2 Replies)
Discussion started by: 915086731
2 Replies

3. Shell Programming and Scripting

passing parameters from a script to a datastage job

We have a requirement as follows. We have created a datastage job that will be doing the select operation from table (select query from a table). The datastage job is being invoked by a unix shell script(ksh). We are passing the "table name (STUD_DETAILS)" and a "where clause condition... (4 Replies)
Discussion started by: kmanivan82
4 Replies

4. UNIX for Dummies Questions & Answers

Problem with Input Parameters using Shell Script

i have this basic code that accepts for two input one for the source file and the other is for the target directory. basically it is a simple copy command. the problem is at the end of the execution the second parameter string was passed to first parameter and it displays a message like: cp:... (3 Replies)
Discussion started by: wtolentino
3 Replies

5. UNIX for Dummies Questions & Answers

Capturing Input Parameters on Shell Script

i have this basic line of code that doesn't work. i simply want to get the input parameter strings but when the script is run it appears that the first parameter is assigning the value to the second parameter. #!/bin/sh pdir=`pwd` p1=$1 p2=$2 echo "directory: $pdir\n" echo "parameter... (2 Replies)
Discussion started by: wtolentino
2 Replies

6. Shell Programming and Scripting

Input parameters

I have a script which take 3 input parameters 1st - a date (i.e. current date) 2nd - type (i.e. A) 3rd - limit (i.e. 40) normally the date parameter would be current date, so I thought I could do this calculate.sh $(date +%Y-%m-%d) A 40 however, it seems like it can't be done,... (3 Replies)
Discussion started by: mpang_
3 Replies

7. Shell Programming and Scripting

DB2 stored procedure (with input parameters) from script

I have a db2 stored procedure on my database which require 3 parameters, I have the following db2 command in a sql script CONNECT TO SAMPLE; CALL BACKUP(INPUT_1, INPUT_2, INPUT3); Usually, I would just invoke this sql script from my shell script like below db2 -tf... (1 Reply)
Discussion started by: mpang_
1 Replies

8. Shell Programming and Scripting

Help with parsing parameters

Hi:- I need to parse a script 3 parameters (file, subject and email address). This is what I currently have: allargs=$* argcount=`echo $allargs | awk -F: '{ print NF }' ` # Total Number of arguments pdffile=`echo $allargs | awk -F: '{ print $1 }' ` # PDF/binary file to be encoded... (4 Replies)
Discussion started by: janet
4 Replies

9. Shell Programming and Scripting

Parsing input paramter in a script

Hi folks I am having a little trouble in parsing a variable read into a ksh script I have a bunch of variables passed into script test.ksh HOST SERVER JOB1 JOB2 JOB3 JOB4 JOB5 What I want to do is read all the $JOB variables ($JOB1, $JOB2, $JOB3) into a variable and then read that variable... (2 Replies)
Discussion started by: Anubhav
2 Replies

10. Shell Programming and Scripting

Parsing Parameters

How do you pass parameters over to another script and run the receiving script? . Here is an example of what I am talking about. for x in `cat Allx` do su myaccount -c "/temp/scripts/temp_script $x" > /dev/null 2>$1 $ done I was expecting the tem_script to be... (1 Reply)
Discussion started by: odogbolu98
1 Replies
Login or Register to Ask a Question