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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to Strip File Down

Status
Not open for further replies.

rhearn

IS-IT--Management
Nov 6, 2000
22
0
0
CA
I am having a problem pulling required info from a file.


There are thousands of records on this file. I have only included 2.

Here is an example of the file:


00000 (Beginning of one of many records)
00001 (some data)
00002 (some data)
00003 (account name)
00004 (some data)
00005 (some data)
99999 (End of this record)
00000 (Beginning of next record)
00001 (some data)
00002 (some data)
00003 (account name)
00004 (some data)
00005 (some data)
99999 (End of this record
etc..., etc....

What I need to do is pull all 00000 to 99999 records
that have a specific account name only and put these records out to a new file.
Account name always has 00003 as it's identifier.

Does someone have any idea if this can be accomplished???
And if so how?????

Thanks in advance.

Rich.
 
take a look at fseek and rewind in your man pages they may help you with what you need to do. use the rewind to get to the first chunk of data once your condition has been set, set a switch so that you copy until you get a 99999 record.

hope this helps
 
Here's a quick shell script. Not the most effecient way, but it's a quick code.
Basically, it saves the records in a temporary file until the 99999 code is reached. If there was a company match before then it copies the record to the output file. Make sure that the printf statement puts the data back out in the way you are expecting.
---------------------------------------------------------------------------

#!/bin/ksh
DATA1=data1 # Input Data File
DATA2=data2 # Temp Data File
DATA3=data3 # Output Data File
COMPANY="IBM" # Company Name

KEEPREC=0

while read RECTYPE RECDATA
do
# Save the record to tempory data file DATA2
printf "%s %s\n" "$RECTYPE" "$RECDATA" >>$DATA2

case $RECTYPE in
# Company name
00003) if [ "$RECDATA" = "$COMPANY" ]
then
KEEPREC=1
else
KEEPREC=0
fi
;;

# End Record
99999) if [ $KEEPREC -eq 1 ]
then
cat $DATA2 >>$DATA3
fi

KEEPREC=0 # Reset Keep Record value
rm $DATA2 # Remove temp file
;;

*) ;;
esac
done <$DATA1

--------------------------------------------------------------------------
Good luck!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top