lundi 23 mars 2020

bash - extract information from a file including search patterns

I am trying to use sed to print the contents between two patterns including the first one. I was using this answer as a source.

My file looks like this:

>item_1
abcabcabacabcabcabcabcabacabcabcabcabcabacabcabc
>item_2
bcdbcdbcdbcdbbcdbcdbcdbcdbbcdbcdbcdbcdbbcdbcdbcdbcdbbcdbcdbcdbcdb
>item_3
cdecde
>item_4
defdefdefdefdefdefdef

I want it to start searching from item_2 (and include) and finish at next occuring > (not include). So my code is sed -n '/item_2/,/>/{/>/!p;}'.

The result wanted is:

item_2
bcdbcdbcdbcdbbcdbcdbcdbcdbbcdbcdbcdbcdbbcdbcdbcdbcdbbcdbcdbcdbcdb

but I get it without item_2.

Any ideas?

Aucun commentaire:

Enregistrer un commentaire