cancel
Showing results for 
Search instead for 
Did you mean: 

Output formatting

Raj_38
Occasional Advisor

Output formatting

File attached with detail requirement.
Please help. Very urgent.

Thanks
10 REPLIES
Michael Steele_2
Honored Contributor

Re: Output formatting

1SUM=0
2SUM=0
3SUM=0

cat FILE | while read DEPT DATE CUST RES
do

case $DEPT in
DEPT1) 1SUM=$(($1SUM+1));;
DEPT2) 2SUM=$(($2SUM+1));;
DEPT3) 3SUM=$(($3SUM+1));;
esac

done
Support Fatherhood - Stop Family Law
Graham Cameron_1
Honored Contributor

Re: Output formatting

Raj
I'd like to help, this should be trivial since you have only 1 table, but you don't give enough information.
What is a "recent 2 contact", likewise 5 and 3 ??

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
john korterman
Honored Contributor

Re: Output formatting

Hi Rai,

if the "recent contacts" are those in your original input file, then try running the attached script with your input file as $1.
If not, please explain "recent".

regards,
John K.
it would be nice if you always got a second chance
Raj_38
Occasional Advisor

Re: Output formatting

I'm surprised to see all have opted for shell script rather than oracle procedure...
anyway.....let me explain more clearly....

Yes i have all details in one single database table.

Attached document with more details...hope i'm making myself clear....



Raj_38
Occasional Advisor

Re: Output formatting

Is the reqmnt not clear ? Urgent pls.

Thanks
Raj
Rodney Hills
Honored Contributor

Re: Output formatting

If we assume your departments are named "DEPT1","DEPT2", and "DEPT3" and that the dates are zero filled 2 digit, then the following perl script may do the trick-

%numhold=("DEPT1",1,"DEPT2",4,"DEPT3",2);
while() {
chomp;
($dept,$date,$cust,$rslt)=split('\s+',$_);
($m,$d,$y)=split("/",$date); $y+=$y < 10 ? 2000 : 1900;
$ymd="$y/$m/$d";
$datum=$hold{$cust}{$dept};
$datum=[] unless $datum;
push(@{$datum},$ymd . "+" . $rslt);
@{$datum}=(reverse sort @{$datum})[0..$numhold{$dept}];
$hold{$cust}{$dept}=$datum;
}
foreach $cust (sort keys %hold) {
print $cust;
foreach $dept ("DEPT1","DEPT2","DEPT3") {
print "+$dept";
foreach $datex (1..$numhold{$dept}) {
print "+$hold{$cust}{$dept}[$datex]";
}
}
print "\n";
}

The date format will be re-arranged to Y/M/D format (easier for sorts).

To run-
perl thisscript newformat

This script also has the benefits if a customer lets say only has 1 contact to DEPT1, then the second contact data will be still have a place holder.

HTH

-- Rod Hills
There be dragons...
Rodney Hills
Honored Contributor

Re: Output formatting

PS-

If the data you are processing is in an Oracle DB (or any other DB), then perl can access the DB directly without the need of an export file.

-- Rod Hills
There be dragons...
Raj_38
Occasional Advisor

Re: Output formatting

My data is available in Oracle database.
I can either use Oracle procedure for this or unix shell script. I cannot use pearl script or others.

Thanks
Raj
Rodney Hills
Honored Contributor

Re: Output formatting

If you are running hp-ux (which I assume that's why you posted to this forum), then "perl" is available on your system.

The script above is assuming a flat text file to process.

-- Rod Hills
There be dragons...
Graham Cameron_1
Honored Contributor

Re: Output formatting

Well, it's a pretty odd request, and your example output doesn't match the stipulated format, but I think the attached will do what you're after. Save it as a .sql file and run from sqlplus.
You'll have to tweak the table and col names, (shown in upper case) as I don't know your exact ones.

-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.