reading a file extracting information writing to a file

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

any help appreciated

Bruce

If you are satisfied with the value of "today", try placing it in double quotes:

...grep "${today}" ...

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.

Without seeing a sample of the input file, we will be guessing here.

Please display a sample of your file.

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

Following awk statement, are you sure it is dong what you want?

details=$( echo "${line}" | cut -c0-300 | awk 'substr($0,266,10)=="          "' | cut -c0-37 )

You can debug the issue by executing the script with set -x .

There are lot of cut commands which may be the culprit.

--ahamed

--ahamed

At the first line:

 today=`date +%c%m%d | cut -c24-31`
 echo ${today}

what should it display?
When I try (OK AIX 4.2.1...) I get:

page:/etc $  today=`date +%c%m%d | cut -c24-31`
page:/etc $  echo ${today}
11012

Is that what you want? (I would have expected 111012...)
If its 111012 then why not simply:

page:/etc $ TODAY=$(date "+%y%m%d")
page:/etc $ echo $TODAY
111012

Ah Im using ksh...

today should give 20111012 and does on HP-UX

ant:/sm/cron/bin $ model;uname;uname -r       
9000/800/L2000-54
HP-UX
B.11.11
ant:/sm/cron/bin $ TODAY=$(date "+%Y%m%d") 
ant:/sm/cron/bin $ echo $TODAY                
20111012
ant:/sm/cron/bin $ 

Shows why we aim forumers to specify what OS and shell they are using...