jeudi 21 septembre 2017

sed print text between 2 pattern and select n occurence

I've been passing hour to search on the net but i can't find a solution to a problem that looks just so easy...

i have a file with multiple pattern match

----PATERN1----
textaa1
textbb1
textcc1
.......
----PATERN2----
----PATERN1----
textaa2
textbb2
textcc2
.......
----PATERN2----
----PATERN1----
textaa2
textbb2
textcc2
.......
----PATERN2----
etc...

This is the output i get with the command

sed -n '/PATERN1/,/PATERN2/p' file

But the question is how can i chose only the nth occurence ? (1 - 2- 3 etc.. that i can then replace with a variable) Thanks in advance

Aucun commentaire:

Enregistrer un commentaire