Hi
I am trying to extract information out of a file but keep getting grep cant open errors
the code is below:
#bash
#extract orders with blank address details
#
# obtain the current date
# set today to the current date ccyymmdd format
today=`date +%c%m%d | cut -c24-31`
echo ${today}
#infile
INFILE=/usr4/xj/data/XJFOMT01
#create a file
OUTFILE=${HOME}/inc13874.${today}.txt
if [ -f ${OUTFILE}]
then
NUM=`wc -l ${OUTFILE}`
else
NUM=0
fi
#get all orders for today that have blank addresses
#perhaps place in file or on stack
while read line
do
details=$(grep ${today} ${line} | cut -c0-300 | awk 'substr($0,266,10)==" "' | cut -c0-37)
DEPOT=$(cut -c0-5 ${details})
COM=$(cut -c6-7 ${details})
ORDER=$(cut -c8-13 ${details})
ODATE=$(cut -c14-21 ${details})
NADID=$(cut -c26-37 ${details})
echo $( 'ODATE ' ${ODATE} 'ORDER ' ${ORDER} 'DEPOT ' ${DEPOT} 'NAD ID ' ${NADID} > ${OUTFILE})
done < ${INFILE}
exit
There is probably a very basic error, I have change ` to $( ) with no improvement and changed ${details} to $details no improvement
and ODATE is not visible
thanks.
The script has had to be changed due to the fact that the grep or cut command required the data to be passed in a different way otherwise the original 'line' or 'details' was altered.
#bash
#extract orders with blank address details
#
# obtain the current date
# set today to the current date ccyymmdd format
today=`date +%c%m%d | cut -c21-28`
echo ${today}
#
#infile
INFILE=/usr4/xj/data/XJFOMT01
echo ${INFILE}
#create a file
OUTFILE=${HOME}/inc13874.${today}.txt
if [ -f ${OUTFILE} ]
then
NUM=`wc -l ${OUTFILE}`
else
NUM=0
fi
echo ${NUM} ' ' ${OUTFILE}
#get all orders for today that have blank addresses
#perhaps place in file or on stack
$( echo 'ODATE ORDER DEPOT NAD ID ' > ${OUTFILE} )
while read line
do
echo ${line}
details=$( echo "${line}" | cut -c0-300 | awk 'substr($0,266,10)==" "' |cut -c0-37 )
DEPOT=$( echo "${details}" | cut -c0-5 )
COM=$( echo "${details}" | cut -c6-7 )
ORDER=$( echo "${details}" | cut -c8-13 )
ODATE=$( echo "${details}" | cut -c14-21 )
NADID=$( echo "${details}" | cut -c26-37 )
echo 'line ' "${ODATE}"
#if [ "${ODATE}" == "${today}" ]
# then
# $( echo 'ODATE ' "${ODATE}" 'ORDER ' "${ORDER}" 'DEPOT ' "${DEPOT}" 'NAD ID ' "${NADID}" >> "${OUTFILE}" )
#fi
done < ${INFILE}
#ADDRESS=$(grep ${ORDER} XJFADT01 | cut -c47-320)
# mailx -s "blank orders inc13874" emailaddress < ${OUTFILE}
exit
The current problem is that the variables are not being populated
---------- Post updated at 02:06 PM ---------- Previous update was at 02:05 PM ----------
the
echo ${line}
returns the expected data by within do loop variables remain blank.
This is a sample of the record - line is shown in 80 byte segments but is actually a continuous stream of 900ish characters all characters are text.
SYD WW20049120110928SAU SYD010000045001 VYG774AHE 234546235036N00100001
00001000000000012BX 2011092800011700 G 48N HZ N MIN
EALLMINE 050 BY 0000000000000 0000000002000AUD0000000000000000
201109282350G774AHE C BRUCE 21 SI
MMER PIECE FENS
5374 BROWNLOW 02 456456
BRUCE Y
YY16001 SYD 5646464 AU N
N N
C N
I am wondering if I can open and close a file in the same script. Then reopen.
open output
close
open input
---------- Post updated at 03:50 PM ---------- Previous update was at 03:49 PM ----------
there are many records in the file I have shown only 1 to indicate how the data looks