Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nawk script appears to be truncating data

Status
Not open for further replies.

confuseddddd

Programmer
May 22, 2003
53
US
Have the following nawk script and appears the file is being truncated...
The script reads the current date, reads the input file for every occurance of BBIL and then writes out all records between each BBIL to a specific person's file; however, appears some of the records are being truncated. There is no length given, so why would the truncation occur??? Is there an assumption within a nawk script that the record length is 512, if so, how can we increase that???

nawk 'BEGIN{
FS=" "
PRE='`date -u +%Y%m%d`'

XXXCNT=0
TOTBILL=0
}

##Now the main loop begins, looking for all BBIL (start of bill) records
##If BBIL, then 2nd field, position 17, for a length of 3, will be the user id
{
if ( substr($1,1,4) == "BBIL" ) {
VAR=substr($2, 17, 3)
TOTBILL+=1

##Test if VAR is a valid user
##If not valid user, then set user to XXX and increment XXX count
if ( VAR != "VML" && VAR != "CAT" && VAR != "REG" && VAR != "HYD" && VAR != "DDS" && VAR != "PJM" && VAR != "BQT" && VAR != "JXB" && VAR != "GGL" && VAR != "NAJ" &&
VAR != "SQF" && VAR != "TTY" && VAR != "PKP" && VAR != "MAW" )
{
VAR="XXX"
XXXCNT+=1
}
#
}
#
## Substitute the trailing spaces with null values
## Send input records to user output files
sub(/ *.$/,"")
print $0 >> PRE"_I01."VAR
}
 
sub(/ *.$/,"")
This will delete all spaces and ANY last character.
BTW, nawk don't feel comfortable with binary files.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top