Skip to main content
added 335 characters in body
Source Link

I have a list of data, separated into blocks by headlines. The headlines are marked by 6 '=' signs at beginning and end. There is a limited set of headlines that may appear, but not all of them appear every time. They will however appear in the same order every time. The amount of data in each block varies. I would like to reverse the order of two specific textblocks in this set of data. (Clarification: Not the order of the data inside the block, but the order the block get printed in)

Edit: Another Clarification: There is a limited number of different headlines, and I want to reverse two specific ones that I know the content of, but not where in the file they appear. There may even be cases where only one or none of the two appear. If they appear, they will always appear right after each other in the same order.

Sample input:

======abc======
data1
data2
data3
======def======
data4
======ghi======
data5
data6
======jkl======
data7
======mno======
data8

desired output:

======abc======
data1
data2
data3
======def======
data4
======jkl======
data7
======ghi======
data5
data6
======mno======
data8

If I add empty lines before each headline using sed '/======.*======/i\\', then using something like this answer might work, but haven't ever used perl and don't know how to modify it to do what I want. Also I suspect awk might be able to do this.

I have a list of data, separated into blocks by headlines. The headlines are marked by 6 '=' signs at beginning and end. There is a limited set of headlines that may appear, but not all of them appear every time. They will however appear in the same order every time. The amount of data in each block varies. I would like to reverse the order of two specific textblocks in this set of data. (Clarification: Not the order of the data inside the block, but the order the block get printed in)

Sample input:

======abc======
data1
data2
data3
======def======
data4
======ghi======
data5
data6
======jkl======
data7
======mno======
data8

desired output:

======abc======
data1
data2
data3
======def======
data4
======jkl======
data7
======ghi======
data5
data6
======mno======
data8

If I add empty lines before each headline using sed '/======.*======/i\\', then using something like this answer might work, but haven't ever used perl and don't know how to modify it to do what I want. Also I suspect awk might be able to do this.

I have a list of data, separated into blocks by headlines. The headlines are marked by 6 '=' signs at beginning and end. There is a limited set of headlines that may appear, but not all of them appear every time. They will however appear in the same order every time. The amount of data in each block varies. I would like to reverse the order of two specific textblocks in this set of data. (Clarification: Not the order of the data inside the block, but the order the block get printed in)

Edit: Another Clarification: There is a limited number of different headlines, and I want to reverse two specific ones that I know the content of, but not where in the file they appear. There may even be cases where only one or none of the two appear. If they appear, they will always appear right after each other in the same order.

Sample input:

======abc======
data1
data2
data3
======def======
data4
======ghi======
data5
data6
======jkl======
data7
======mno======
data8

desired output:

======abc======
data1
data2
data3
======def======
data4
======jkl======
data7
======ghi======
data5
data6
======mno======
data8

If I add empty lines before each headline using sed '/======.*======/i\\', then using something like this answer might work, but haven't ever used perl and don't know how to modify it to do what I want. Also I suspect awk might be able to do this.

edited tags
Link
Source Link

Reverse sorting of 2 textblocks in larger set of textblocks

I have a list of data, separated into blocks by headlines. The headlines are marked by 6 '=' signs at beginning and end. There is a limited set of headlines that may appear, but not all of them appear every time. They will however appear in the same order every time. The amount of data in each block varies. I would like to reverse the order of two specific textblocks in this set of data. (Clarification: Not the order of the data inside the block, but the order the block get printed in)

Sample input:

======abc======
data1
data2
data3
======def======
data4
======ghi======
data5
data6
======jkl======
data7
======mno======
data8

desired output:

======abc======
data1
data2
data3
======def======
data4
======jkl======
data7
======ghi======
data5
data6
======mno======
data8

If I add empty lines before each headline using sed '/======.*======/i\\', then using something like this answer might work, but haven't ever used perl and don't know how to modify it to do what I want. Also I suspect awk might be able to do this.