On 24.09.2015 14:39, Piotrzot wrote:
> Hi,
> I work in a GNU-Linux environment. gawk is available.
That's fine. In case the Linux distribution is too old (version 3
is still delivered) download the latest gawk 4.1.3 version
> But I wasn't able to understand how to use the sorting functions.
I'm still unsure about your programming skills and awk knowledge.
>
> Usually, i try to solve problems by my self, surfing the net. But it's frustrating sometimes.
I would solve the issue in two steps.
The first is to sort the blocks; awk supports a method to process
such blank-line-separated blocks (multi-line records) by setting
RS="". Then sort the records; either inspect the gawk manual about
defining an own sorting function to compare the date value, or use
a common trick to (temporarily) prepend the date (i.e. your second
field) as first element to the block, then sort, and remove that
element after the sorting.
The second step would be to arrange the lines in each block in the
desired order. In case you have a known set of keywords you can
collect (concatenate them, because of multiple entry AUTHOR) the
entries in respective variables, and if you encounter a blank line
(or the end of the file; use awk's END clause) you can print out
the variables in the desired order, and clear them for the next
block.
>
> Ideally, I would prefert the "right" link to a tutorial/discussion.
The GNU awk manual (Arnold Robbins book) would provide you with
all details. There you find also sort functions described. In case
what I wrote above makes no sense to you it's worth to start from
the beginning. Otherwise you're also welcome if you have concrete
questions.
Janis