Help parsing job script input parameters

I have a job script that runs with input parms from the command line.

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

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

try if the below helps

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

Worked awesome.
Thanks so much

you are welcome :slight_smile: