I'm trying to do something like this but for quoted emails, so this
On 2014-07-11 at 03:36 PM, <[email protected]> wrote:
>Hi Everyone,
>
>
>
>I love spaces.
>
>
>
>That's all.
Would become this
On 2014-07-11 at 03:36 PM, <[email protected]> wrote:
>Hi Everyone,
>
>I love spaces.
>
>That's all.
Thanks
Another awk-based solution:
awk '{ /^>\s*$/?b++:b=0; if (b<=1) print }' file
Breakdown:
/^>\s*$/?b++:b=0
- ? : the ternary operator
- /^>\s*$/ matches a blank line starts with ">"
- b variable that counts consecutive blank lines (b++).
however, if the current line is non-blank, b is reset to 0.
if (b<=1) print
print if the current line is non-blank (b==0)
or if there is only one blank line (b==1).
Assuming that each visual line is a proper logical line (string of characters ended with a \n
), you can dispense with the rest of the tools and simply run uniq(1)
on the input.
Example follows.
% cat tst
>Hi Everyone,
>
>
>
>I love spaces.
>
>
>
>That's all.
% uniq tst
>Hi Everyone,
>
>I love spaces.
>
>That's all.
%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With