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

test column values

Status
Not open for further replies.

loujako

Technical User
Feb 28, 2017
3
DZ
I've file with 2 columns
Cla Clb
5301 1922
5301 1923
5301 1925
5311 2020
5311 2021
5311 2022
5321 1880
5321 1885
5321 1886
5321 1887
... ...
I need to find cumul of diffrence values upper than 1 on column b with the same value of column a
if value of Cla is the same ex: 5301 do (1925-1923=2),(1923-1922=1) : cumul difference > 1 is equal 1 so cumul1=1
second value of Cla 5311 do (2022-2021=1), (2021-2020=1) : cumul difference > 1 is 0 so cumul2=0
third value of Cla 5321 (1887-1886=1), (1886-1885=1); (1885-1880=5) cumul difference > 1 is 1 so cumul3=1
at the end I'll calculate cumul1+cumul2+cumul3+...cumuln
using bash script or awk
attached wall file test
thanks for your help
 
 http://files.engineering.com/getfile.aspx?folder=d47fa08d-f1c3-44d0-bae0-a9e17ea148ef&file=test.txt
Hi

So if there is at least one case when the difference between consecutive Clb values is greater than 1, then the cumul of the given Cla group is 1, otherwise 0 ?
Code:
NR [teal]==[/teal] [purple]1[/purple] [teal]{[/teal] [b]next[/b] [teal]}[/teal]
last[teal][[/teal][navy]$1[/navy][teal]] && ![/teal] cumul[teal][[/teal][navy]$1[/navy][teal]] {[/teal] cumul[teal][[/teal][navy]$1[/navy][teal]] =[/teal] [navy]$2[/navy] - last[teal][[/teal][navy]$1[/navy][teal]] >[/teal] [purple]1[/purple] [teal]}[/teal]
[teal]{[/teal] last[teal][[/teal][navy]$1[/navy][teal]] =[/teal] [navy]$2[/navy] [teal]}[/teal]
[b]END[/b] [teal]{[/teal] [b]for[/b] [teal]([/teal]i [b]in[/b] cumul[teal])[/teal] [b]printf[/b] [i][green]"cumul %s = %s[/green][/i][lime]\n[/lime][i][green]"[/green][/i][teal],[/teal] i[teal],[/teal] cumul[teal][[/teal]i[teal]] }[/teal]


Feherke.
feherke.ga
 
thanks for your prompt response
the programm work but it do not the cumul like I need. in my example:
5301 1922
5301 1923
5301 1925
5301 1927

5311 2020
5311 2021
5311 2022
5311 2024

5321 1880
5321 1885
5321 1886
5321 1887
ze test :
for $1=5301 we have (1923-1922=1); (1925-1923)=2; (1927-1925=2) cumul difference must be >1 cumul1= 0+2-1+2-1=2
for $1=5311 we have (2021-2020=0);(2022-2021=0);(2024-2022=2) cumul difference > 1 cumul2= 0+0+2-1=1
for $1=5321 we have (1887-1886=1);(1886-1885=1);(1885-1880=5) cumul difference > 1 cumul3= 0+0+5-1=4
the program do just one operation of difference
so
for a value of Cla we do val(n)-val(n-1)=a1; val(n-1)-val(n-2)=a2;...... and the cumul is if diff > 1 a1-1+a2-1+a3-1+.....
thanks a lot
execuse me for my longue explanation
 
Hi

Not really sure as I can not find the relation between your "we have" values and "cumulX=" values, but maybe this :
Code:
NR [teal]==[/teal] [purple]1[/purple] [teal]{[/teal] [b]next[/b] [teal]}[/teal]
last[teal][[/teal][navy]$1[/navy][teal]] {[/teal] diff [teal]=[/teal] [navy]$2[/navy] - last[teal][[/teal][navy]$1[/navy][teal]];[/teal] [b]if[/b] [teal]([/teal]diff [teal]>[/teal] [purple]1[/purple][teal])[/teal] cumul[teal][[/teal][navy]$1[/navy][teal]] +=[/teal] diff - [purple]1[/purple] [teal]}[/teal]
[teal]{[/teal] last[teal][[/teal][navy]$1[/navy][teal]] =[/teal] [navy]$2[/navy] [teal]}[/teal]
[b]END[/b] [teal]{[/teal] [b]for[/b] [teal]([/teal]i [b]in[/b] cumul[teal])[/teal] [b]printf[/b] [i][green]"cumul %s = %s[/green][/i][lime]\n[/lime][i][green]"[/green][/i][teal],[/teal] i[teal],[/teal] cumul[teal][[/teal]i[teal]] }[/teal]

Feherke.
feherke.ga
 
I've tested your programm it work fine I'll test it on the entire file. I'll write to you about result
thank you so much quick reply and your interest.
good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top