I asked what OS and shell you're using. You have now given us the OS. Are you restricting yourself to only using /bin/sh
on Solaris 10? (Your code can be much shorter and more efficient if you're willing to use /bin/ksh
, /usr/xpg4/bin/sh
, or /usr/xpg6/bin/sh
, or /bin/bash
instead of /bin/sh
.)
I am glad that this is not homework. There are special rules and a special forum where homework assignments are to be submitted. Homework assignments frequently include a small list of utilities that can be used to complete the assignment. So saying that you can't use awk
and sed
made this look like a homework assignment. Why don't you want to use awk
or sed
? You have said you want a short script that will give you exact results. You have shown us about 15 lines of code (using sed
which you said we can't use) and you haven't solved the problem yet. (And you made a leap of logic that I can't follow between the file you named headerfile
in post #1 and the file you named header
in post #6 in this thread???
Why wasn't the line:
*FileHeader* Partition 0
a header in post #1? Where did the SCHEMA.TABLEdigit
come from in post #6 and why do you want to the last two segments to the same file ( SCHEMA.TABLE3
) which will throw away the contents of the 3rd segment?
You are right. I am not a teacher. My father was a teacher. I got my degrees in computer science and computer engineering more than four decades ago, and I am still a student learning new things about my chosen field every day. If you aren't here to learn; you're in the wrong place. If you're here expecting us to serve as your unpaid programming staff; you're in the wrong place.
If you were willing to use awk
and I guessed correctly while making a lot a wild assumptions based on your incomplete design requirements, I would suggest you try something like:
#!/bin/sh
/usr/xpg4/bin/awk '
/Partition/ { if(fn++) close(file); file = "SCHEMA.TABLE" fn }
file != "" { print > file }
' file1
which is a total of 5 lines of code and gives exact results. The awk
script could be turned into a single line, but I will choose readable code (rather than the minimum number of lines of code) every time. With the data you showed us in file1
in your 1st post, this script produce the four files:
SCHEMA.TABLE1
:
*FileHeader* Partition 0
Total Data Bytes 1416
Avg Bytes/Record 1416
Others 1
SCHEMA.TABLE2
:
PRDX22.AUDIT_DATA_INFO Partition 4
Total Data Bytes 4615
Avg Bytes/Record 100
Delete 11
Insert 35
Before Images 11
After Images 35
SCHEMA.TABLE3
:
PRDX22.AUDIT_TRAIL Partition 4
Total Data Bytes 12317
Avg Bytes/Record 362
Delete 4
Insert 30
Before Images 4
After Images 30
and SCHEMA.TABLE4
:
PRDX22.CONTACT Partition 4
Total Data Bytes 21252
Avg Bytes/Record 442
Insert 1
FieldComp 47
After Images 48