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

Transfor data problem 3

Status
Not open for further replies.

fabien

Technical User
Sep 25, 2001
299
AU
Hi!

I have the following input data file:
782341.2 1184897. 1.000000
782420.8 1184892. 1.000000
782460.0 1184809. 1.000000
782568.9 1184796. 1.000000
782651.7 1184739. 2.000000
782764.9 1184770. 2.000000
782860.8 1184722. 2.000000
782965.3 1184761. 2.000000
783096.0 1184752. 2.000000

I want to obtain the following:
782341.200 1184897.000999999999999 6 1
782420.800 1184892.000999999999999 7 1
782460.000 1184809.000999999999999 7 1
782568.900 1184796.000999999999999 8 1
782651.700 1184739.000999999999999 6 2
782764.900 1184770.000999999999999 7 2
782860.800 1184722.000999999999999 7 2
782965.300 1184761.000999999999999 7 2
783096.000 1184752.000999999999999 8 2

Can someone please help?

Many thanks!
 
Take a look at the printf function.
How you determine the value of the 3rd column (6, 7 or 8) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

A segment is defined as: first point should be 6, last point is 8 and 7's in between. A change in 3rd column changes (i.e from 1 to 2)will mean a new segment.

Thanks,
 
Sorry to be so dense, but given your input sample and your expected result, I quite don't understand the rule for this column: 6, 7 or 8.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Try

NR>1{
k = 7
if (!flg) k = 6
flg = 1
if (f3 != $3) {
k = 8
flg = 0
}
printf("%11.3f %s000999999999999%3d%6d\n",f1,f2,k,f3)
}
{
f1 = $1
f2 = $2
f3 = $3
}
END {
k = 8
printf("%11.3f %s000999999999999%3d%6d\n",f1,f2,k,f3)
}

CaKiwi
 
Something like this ?
BEGIN{fmt="%12.3f%12.3f999999999999%3d%5d\n"}
$3!=s{
if(NR>1)printf fmt,x,y,8,s
x=$1;y=$2;s=$3;p=6
next
}
{ printf fmt,x,y,p,s
x=$1;y=$2;s=$3;p=7
}
END{if(NR>1)printf fmt,x,y,8,s}

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 

This works (I tested it):

Code:
{ pr()
  f1=$1; f2=$2; f3=$3
  k = (8==k) ? 6 : 7
}
END { pr() }

function pr(      format) {
  if (f3!=$3) k=8
  format = "%11.3f %s000999999999999%2d%5d\n"
  if (f1)
    printf(format,f1,f2,k,f3)
}
 
Thanks a lot guys your solutions worked equally well just a few differences in output formats.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top