mardi 23 janvier 2018

Print lines from text file splitted into parts by a pattern in bash

I have a text file like this:

line 1  
line 2
* 
line 3
* 
line 4 
line 5 
line 6
*
line 7
line 8

I would like to write out parts which are between the two patterns (* in this case). So if I want the first section, I want to get

line 1
line 2

If I want to get the third one it should be

line 4
line 5
line 6

The returned lines should be without the asterisk, and it is important that there is no asterisk at the beginning or at the end. I was thinking about "splitting" the whole text into columns using '*' as delimiter with sed or awk, but I did not succeed. Anyone could help? Thanks a lot.

Aucun commentaire:

Enregistrer un commentaire