I am trying to edit a json file, and I need to take out the lines starting and ending with {%
and %}
respectively and move them to the beginning of the file. I need to do it at different places in a single file and repeat it for a lot of files, hence I am looking for a single command to this for one place and then I can repeat it again and again.
Ex. Current file:
{% data 1 %}
{
"data1": [
detail1a: data detail 1a
detail1b: data detail 1b
]
}
{% data 2a %}
{% data 2b %}
{
"data2": [
detail2a: data detail 2a
detail2b: data detail 2b
]
}
{% data 3a %}
{
"data3": [
detail3a: data detail 3a
]
}
In this file, i want to remove all the data xa/xb lines and paste them at the beginning of the file like:
{% data 1 %}
{% data 2a %}
{% data 2b %}
{% data 3a %}
<rest of the lines>% data 3a %}
Then I can use :%s/^\(\s\+\)]\n}\n{$/\1],/g
to remove the }{ to join it as a single execution.
I can do /^{%.*%}$
to get the line but how do I cut it and move it to line 0 (pushing down whatever is at line 0 already).
Any help appreciated.
PS: This is my first post in stackechange and I tried looking for all the existing posts to my best. The closet I found is this (Cut line, trim it and then paste it on another line) but it doesn't solve my purpose. Please excuse if I missed some norms.