# Shortest POSIX command line that eagerly removes dual newline sequences

Example:

echo -ne 'a\n\nb\nc\n\n\n\nd\n\n\n' | your-command


should output the same as

echo -ne 'ab\ncd\n'


Watch out, some POSIX tools have implementations that diverge from the standard. Please consult https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html before submitting your solutions.

# Sed, 22

sed ':l;s/\n\n//;N;bl'


Try it online!

Initially I had hoped to do sed -z 's/\n\n//g' for a score of 18, but I think -z is a GNU extension and not Posix.

• Sorry, it doesn't work on MacOS. -z option is not present either. (This version of sed was written by Diomidis Spinellis for FreeBSD. It's expected to be a superset of the IEEE Std 1003.2 (POSIX.2'') specification.) Feb 6 '20 at 18:44
• Figured it out: sed -E ':l;s/\n\n//;N;bl' on MacOS. A known bug. Feb 7 '20 at 12:42

## AWK, 26 22 bytes

awk -vRS='

' -vORS= 1


Tested with gawk and mawk on MacOS.

Edit: saved 4 bytes thanks to @AndersKaseorg.

• You can remove the second "" pair (−2 bytes), and you can replace the \n\n with two literal newlines (−2 bytes). Feb 6 '20 at 9:21

# Bash, 32 bytes

awk 'BEGIN{RS="\n\n";ORS="";} 1'


Try it online!

• I'm not talking about practical use though. I'm saying your answer is invalid, since nothing in the challenge's spec says you can assume there's a character that's not in the input string. Feb 6 '20 at 17:14
• Feb 6 '20 at 17:34
• Your answer is invalid regardless of tags. Most standard loopholes (including this one) aren’t tag-specific. Feb 7 '20 at 9:32
• @Grimmy Ah, didn't know that - thanks for bring me up to speed. :-) Feb 7 '20 at 11:07
• @Grimmy Fixed that. Feb 7 '20 at 11:35