Example data.in hundreds of blocks that look something like that
The numbers of lines with numbers is always odd.
So if I need to extract the middle row first column of block one the code
will return 31. If I change #S 1 to #S 2 will give me the result 52.
Is it possible to automate that procedure.
The desired output would be.
The only way I can think of doing this is via for loop in bash that would call the awk script above.
Is there another way of doing this entirely in awk.
Probably I need to find another way of extracting the desired element without the use of
END{...} block. Then I can define that as a function in awk and call that function for each occurrence of the regular expression #S.
Thanks
Code:
#S 1
a b c d
11 2 3 0
31 5 6 1
72 8 9 2
end block one
#S 2
a f g h
24 3 4 0
62 7 8 1
52 6 8 2
45 7 9 3
87 4 1 4
end block two
#S 3
d g k j
11 4 5 0
33 1 3 1
43 4 6 2
end block three
So if I need to extract the middle row first column of block one the code
Code:
awk '/#S 1/,/end/{
if($0!~/[a-z]/) vec[++nr,1]= sprintf("%i\n", $1) }
END{print vec[int((nr+1)/2),1]}' data.in
Is it possible to automate that procedure.
The desired output would be.
Code:
1 31
2 52
3 33
Is there another way of doing this entirely in awk.
Probably I need to find another way of extracting the desired element without the use of
END{...} block. Then I can define that as a function in awk and call that function for each occurrence of the regular expression #S.
Thanks