-
-
Save x-yuri/e3c366893ba8b6c07385f6822a3ba904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- /home/yuri/_/1.sh 2019-03-31 17:56:18.380352272 +0300 | |
+++ /home/yuri/_/2.sh 2019-03-31 17:56:05.463685315 +0300 | |
@@ -13,11 +13,11 @@ | |
3 | |
] | |
...' | |
-sed -ne ' ;# "-n" suppresses autoprint of pattern space | |
- /^\[/!d ;# skip lines that donot begin a fresh block | |
- :a;$!N;/\n]/!ba ;# keep appending lines to pattern space until end of block | |
+sed -Ene ' ;# "-n" suppresses autoprint of pattern space | |
+ /^\[$/!d ;# skip lines that donot begin a fresh block | |
+ :a;N;/\n]$/!ba ;# keep appending lines to pattern space until end of block | |
G ;# append our makeshift counter (hold space) to pattern spc | |
- s/\n\{2\}$//p ;# only when counter had 2 chars in it, we print block | |
+ s/\n{2}$//p ;# only when counter had 2 chars in it, we print block | |
/\n$/!q ;# target block, 2nd block has been printed so quit | |
x;s/$/\n/;x ;# target block not reached, so increment | |
' <<<"$file" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
file='... | |
[ | |
1 | |
] | |
... | |
[ | |
2 | |
] | |
... | |
[ | |
3 | |
] | |
...' | |
sed -Ene ' ;# "-n" suppresses autoprint of pattern space | |
/^\[$/!d ;# skip lines that donot begin a fresh block | |
:a;N;/\n]$/!ba ;# keep appending lines to pattern space until end of block | |
G ;# append our makeshift counter (hold space) to pattern spc | |
s/\n{2}$//p ;# only when counter had 2 chars in it, we print block | |
/\n$/!q ;# target block, 2nd block has been printed so quit | |
x;s/$/\n/;x ;# target block not reached, so increment | |
' <<<"$file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment