Scenario:
I'm reading in an ascii file with a header record that has several fields. Layout is:
@@@XXXXXXXXXX999999999DD-MMM-CC999999999
e.g
@@@TEST 00000000301-MAR-02000000025
Where:
@@@ - Identifies the header record
XXXXXXXXXX - File identifier
999999999 (1st) - A run number with leading zero's
DD-MMM-CC - Date
999999999 (2nd) - A Line count with leading zero's
Two of these fields are numbers that I am able to read in by piping the header record to a cut command based on set positions:
RUNNUMBER=`head -1 $FILE | cut -c14-22`
LINECOUNT=`head -1 $FILE | cut -c32-40`
From the example above giving RUNNUMBER = 000000003 and LINECOUNT = 000000025.
My problem is that I need to validate these numbers against numbers read in as parameters e.g
LASTRUNNUM=2
ACTUALLINECOUNT=25
Validation would be something like:
if [[ ! $LINECOUNT = $ACTUALLINECOUNT ]]
then
<report error>
else
<process normally>
fi
And:
if [[ ! $RUNNUMBER > $LASTRUNNUM ]]
then
<report error>
else
<process normally>
fi
I think the best way to compare these numbers would be to strip the leading zero's from the fields read in from the header record. Could someone suggest how to do this?
If not then any other suggestions on what to do?
Cheers!
I'm reading in an ascii file with a header record that has several fields. Layout is:
@@@XXXXXXXXXX999999999DD-MMM-CC999999999
e.g
@@@TEST 00000000301-MAR-02000000025
Where:
@@@ - Identifies the header record
XXXXXXXXXX - File identifier
999999999 (1st) - A run number with leading zero's
DD-MMM-CC - Date
999999999 (2nd) - A Line count with leading zero's
Two of these fields are numbers that I am able to read in by piping the header record to a cut command based on set positions:
RUNNUMBER=`head -1 $FILE | cut -c14-22`
LINECOUNT=`head -1 $FILE | cut -c32-40`
From the example above giving RUNNUMBER = 000000003 and LINECOUNT = 000000025.
My problem is that I need to validate these numbers against numbers read in as parameters e.g
LASTRUNNUM=2
ACTUALLINECOUNT=25
Validation would be something like:
if [[ ! $LINECOUNT = $ACTUALLINECOUNT ]]
then
<report error>
else
<process normally>
fi
And:
if [[ ! $RUNNUMBER > $LASTRUNNUM ]]
then
<report error>
else
<process normally>
fi
I think the best way to compare these numbers would be to strip the leading zero's from the fields read in from the header record. Could someone suggest how to do this?
If not then any other suggestions on what to do?
Cheers!