linux - Pattern decoding II -



linux - Pattern decoding II -

possible duplicate: pattern decoding

i have new question concerning previous post pattern decoding:

i have same info file, there double empty (blank) lines, have taken business relationship in decoding. so, double empty lines mean there street/grout (for definitions see previous post: pattern decoding) in there 0 (0) house, have count these kind of patterns too. (yes, may think, absolutely wrong statement, because there no street without @ to the lowest degree 1 house, analogy, please, take is.)

here new info file, double lines:

0 0 # <--- grouping 1 -- 1 house (0) , 1 room (0) 0 0 # <--- grouping 2 -- 2 houses (0;1) , 3,2 rooms (0,1,2;0,1) 0 1 0 2 1 0 # <--- house 2 in grouping 2, first room (0) 1 1 # <--- house 2 in grouping 2, sec room (1) 0 0 # <--- grouping 3 0 1 # <--- house 1 in grouping 3, sec room (1) 0 2 0 0 # <--- grouping 4 1 0 # <--- house 2 in grouping 4, 1 room (0) 2 0 3 0 # <--- house 4 in grouping 4, 1 room (0) 0 0 # <--- grouping 5 # <--- grouping 6 << ---- new grouping 0 0 # <--- grouping 7 # <--- grouping 8 << ---- new grouping 0 0 # <--- grouping 9 0 0 # <--- grouping 10

i need convert elegant way has been done before, in case have take business relationship these new groups too, , indicate them in way, next kent example: roupidx houseidx numberofrooms, houseidx allow equal 0 houseidx = 0 , numberofrooms allow equal 0 numberofrooms = 0. so, need kind of output example:

1 0 1 2 0 3 2 1 2 3 0 3 4 0 1 4 1 1 4 2 1 4 3 1 5 0 1 6 0 0 7 0 1 8 0 0 9 0 1 10 0 1

can tune previous code in way?

update: new sec empty line indicates new group. if there additional empty new line after empty line, in case

0 0 # <--- grouping 5 # <--- grouping 6 << ---- new grouping 0 0 # <--- grouping 7 # <--- grouping 8 << ---- new grouping

we treat new empty line (the sec 1 in 2 blank lines) new group, , indicate them group_index 0 0. see desired output above!

try:

$ cat houses.awk begin{max=1;group=1} nf==0{ empty++ if (empty==1) group++ next } { max = ($1 > max) ? $1 : max if (empty<=1){ a[group,$1]++ } else { a[group,$1]=-1 } empty=0 } end{for (i=1;i<=group;i++){ (j=0;j<=max;j++){ if (a[i,j]>=1) print , j , a[i,j] if (a[i,j]==-1) print i, j, 0 } printf "\n" } }

command:

awk -f houses.awk houses

output:

1 0 1 2 0 3 2 1 2 3 0 3 4 0 1 4 1 1 4 2 1 4 3 1 5 0 1 6 0 0 7 0 0 8 0 1

linux bash shell sed awk

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -