Hi everyone. I have a text file looking like this:
Book ID: 1
Availability: on shelf > 3 borrows > 2
Name: Bread and Wine
Writer: Silone
Book ID: 2
Availability: on shelf > 4 borrows > 1
Name: Fontamara
Writer: Silone
Book ID: 3
Availability: on shelf > 3 borrows > 2
Name: Poirot
Writer: Agatha Christie
Book ID: 4
Availability: on shelf > 2 borrows > 2
Name: Miss Marple
Writer: Agatha Christie
and so on. I want to count the number of books by each writer and the total amount of their books been borrowed so far, to have a list like this:
-------------
Siolne 2 3
A. Christie 2 4
---------------
I have no idea how to go through this kind of blocks and specially grab a previous line from the block. Any help is appreciated.
Book ID: 1
Availability: on shelf > 3 borrows > 2
Name: Bread and Wine
Writer: Silone
Book ID: 2
Availability: on shelf > 4 borrows > 1
Name: Fontamara
Writer: Silone
Book ID: 3
Availability: on shelf > 3 borrows > 2
Name: Poirot
Writer: Agatha Christie
Book ID: 4
Availability: on shelf > 2 borrows > 2
Name: Miss Marple
Writer: Agatha Christie
and so on. I want to count the number of books by each writer and the total amount of their books been borrowed so far, to have a list like this:
-------------
Siolne 2 3
A. Christie 2 4
---------------
I have no idea how to go through this kind of blocks and specially grab a previous line from the block. Any help is appreciated.
Comment