using substring in shell script

Ah, ok, a now-fringe platform! Does your sed have Extended REs? If not, do you have perl installed?

how to check whether perl is installed or not ?/
how to check sed have extended RE's ......

I have tried by using the code as follows (given by cfajohnson)

#! /bin/ksh
############################
#   AFI Monitor Script
############################

. /db2/uszlad48/sqllib/db2profile
export mondir=/home/bmwdev1/script/krishna/arc
export monlog=$mondir/rcbl1.log

while read line
do
temp=${line#????????????}
trackingnum=${line%"$temp"}
echo $trackingnum
echo "--------"
done < "$monlog"

exit 0

It works fine. I am getting the following output

BEYJYWG83L
--------
BEYJYXMT4K
--------
BEYEHF93QY
--------
BEYJYTT8FQ
--------
BEYJYTT8FQ
--------
BEYJYTT8FQ
--------
BEYJYTT8FQ
--------
BEYJY2SZVL
--------
BEYJY2SXNG
--------
BEYJY2SMS3
--------
BEYJY2SMJD
--------

But how can I extract the other data/fields in following positions.

trackingnumsuffix starting from 14-15 2 bytes
tstampupdated starting from 185-210 26 bytes

Please advice how to proceed furthur.

Krishnakanth

You are not getting any output because there is no statement to give any output.

Add this line:

printf "trackingnum = %s\n" "$trackingnum"

What does it print?

Of course that gives you errors. As I have pointed out before, It is WRONG.

Just type perl and either will either run, or won't be found. If it runs, you have perl.

I mentioned before, and suggested again after, man sed.

You must learn to use and read the man pages - there simply is no way to avoid this in *nix systems.

Your version of expr does not have the substr operator; this is a GNU extension.

Unless you install the GNU utilities, you will have to learn to work within the limitations of the older flavors of the *nix utilities on AIX.

Hi all,

The following code works and I have given the complete code for archiving and purging the records which are older than 1 year.

#! /bin/ksh
############################
#   AFI Monitor Script
############################

. /db2/uszlad48/sqllib/db2profile
export mondir=/home/bmwdev1/script/krishna/arc
export monlog1=$mondir/Archive_ZB_RCBL_ERROR_MSG_MIG_`date +%Y%m%d`.log

# connect to DB
db2 "connect to r2pdev user bmwdevup using summer08"

# extract the records from the table ZB_RCBL_ERROR_MSG_MIG
db2 -x "SELECT * FROM ZB_RCBL_ERROR_MSG_MIG WHERE TIMESTAMP_UPDATED < (CURRENT TIMESTAMP - 1 YEAR) WITH UR" >> "$monlog1"
echo "extraction completed"

while read line
do
	trackingnum=`expr substr "$line" 1 12`
	trackingnumsuffix=`expr substr "$line" 27 6`
	tstmp=`expr substr "$line" 185 26`

#Delete the extracted records one by one
	db2 "DELETE FROM ZB_RCBL_ERROR_MSG_MIG WHERE TRACKING_NUM = '$trackingnum' AND TRACKING_NUM_SUFFIX = $trackingnumsuffix AND TIMESTAMP_UPDATED = '$tstmp'"

done < "$monlog1"
echo "purging completed"

# disconnect from DB2
db2 terminate

exit 0

Thank you very much to all coming forward to help me.

Krishnakanth