I have a massive text file a bit like this:
=?accession=P12345;=?position=999;
=?accession=Q19283;=?position=777;
=?accession=A918282;=?position=888;
and I would like to extract terms between accession=
and ;
, and then also between position=
and ;
so that I get:
P12345 999
Q19283 777
A918282 888
The strings I need to grep between do get more complicated, so I imagine a hardcoded solution.
I know I can take the "grep between two strings" approach:
grep -Po 'accession= \K.*(?= ;)'
but I don't know how to get subsequent extractions from the same line of the input to also appear on the same line as the output.
I really don't mind how this is done as long as I can call it from a linux command line.
Thanks.
You can update your grep expression like this.
Output:
To format it the way you want, use
paste
:Output:
Another simple awk solution :
Output: