Essentially, I'm trying to get the content between two string, but that use the same character repeated N time, like so:
===
This is a test
===
====
Another test
====
==
Last test
==
The above is just an example of course. Here what I tried and their result:
sed -u '/==/!d;s//&\n/;s/.*\n//;:a;/==/bb;$!{n;ba};:b;s//\n&/;P;D' testfile
Give
=
This is a test
=
Another test
Last test
If I were to use only one of the above in the testfile
:
Last test
This would give the wanted result (albeit with too many added newlines but that's fine for this example).
The above works only if there a single instance of those repeated characters or if it is a pair of unique strings enclosing the content...
How can I get the content between two strings using the same number of repeated characters? I prefer to use either grep
, sed
or awk
for this.
=
in between two equal number of=
characters? In other words, wouldsed -nE '/^=+$/,//{//!p}' testfile
fail for your usecase?