perl - using awk to process next column values with current line value -


i new awk, couldn't figure out how process next record columns, appreciated. required:

$ cat sample.csv 1,1,1,30,40,23,24,25,26,27,28,29,0,0,0,0,0,0,0,0 1,2,1,35,40,33,34,35,36,37,38,39,12,13,14,15,16,17,22,36 1,3,1,45,50,43,44,45,46,47,48,49,22,23,24,25,26,27,33,38 

i able half of required, in line 1, not able process line 2 values

$ cat sample.csv | awk -f"," '{a+=$4}{b+=$5}{c+=$6}{d+=$7}{e+=$8}{f+=$9}{g+=$10}{h+=$11}{i+=$12}{j+=$13}{k+=$14}{l+=$15}{m+=$16}{n+=$17}{o+=$18}{p+=$19}end{print "line 1 " a+b-c-d-e-f-g-h}' 

line 1 -399

i looking expression a+b-c-d-e-f-g-h - (nextrecord i+j+k+l+m+n) last record, can consider next record values 0's.

i think end block messing up. limited knowledge of awk includes vaguely similar perl, , @ least in perl end run @ end of process. you're getting single row because telling block of code not run until entire process done executing.

awk -f"," '{a+=$4}{b+=$5}{c+=$6}{d+=$7}{e+=$8}{f+=$9}{g+=$10}{h+=$11}{i+=$12}{j+=$13}{k+=$14}{l+=$15}{m+=$16}{n+=$17}{o+=$18}{p+=$19} {print "line 1 " a+b-c-d-e-f-g-h}' sample.csv 

also note don't need cat file , pipe in awk, accepts file last argument.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -