Subject: Newline badly matched/substituted

From: Gabriel Czernikier <[email-masked]>
Date: Mon, 11 Jun 2018 15:29:41 -0300

sed --version
sed (GNU sed) 4.2.2

uname -o
Cygwin

uname -r
1.7.28(0.271/5/3)

For a file named threaddump.txt which contents delimited by ='s is:
==========================
                at
org/springframework/security/ui/SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)[optimized]

                at
org/springframework/security/util/FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:406)[optimized]

==========================

For which there's just line-feed as line separator (i.e. there's no
carriage-return at all), and just ASCII chars there are whithin.

For unambiguity's sake, the input in question, printed through sed -n l,
delimited by ='s is:
==========================
                at org/springframework/security/ui/SpringSecurityFilt\
er.doFilter(SpringSecurityFilter.java:53)[optimized]$
          $
                at org/springframework/security/util/FilterChainProxy\
$VirtualFilterChain.doFilter(FilterChainProxy.java:406)[optimized]$
          $
==========================

So, the wanted result is the input text transformed so that the newlines
are replaced, one on one, by, let's say, literal 'X's (without quotes). So
the result delimited by ='s, filtered through sed -n l, would be:
==========================
                at org/springframework/security/ui/SpringSecurityFilt\
er.doFilter(SpringSecurityFilter.java:53)X          X                \
at org/springframework/security/util/FilterChainProxy$VirtualFilterCh\
ain.doFilter(FilterChainProxy.java:406)X          X$
==========================

Of a couple of scripts that would seem apropriate to achieve this result,
none of them does it but with littering. Each program invocation followed
by its result, are shown next.
sed '$!N; s/\n/X/g;' threaddump.txt | sed -n l
==========================
                at org/springframework/security/ui/SpringSecurityFilt\
er.doFilter(SpringSecurityFilter.java:53)X          $
                at org/springframework/security/util/FilterChainProxy\
$VirtualFilterChain.doFilter(FilterChainProxy.java:406)X          $
==========================

sed '$!N; s/$/X/mg;' threaddump.txt | sed -n l
==========================
                at org/springframework/security/ui/SpringSecurityFilt\
er.doFilter(SpringSecurityFilter.java:53)X$
          X$
                at org/springframework/security/util/FilterChainProxy\
$VirtualFilterChain.doFilter(FilterChainProxy.java:406)X$
          X$
==========================

sed '$!N; s/$/X/mg; s/\n/X/g;' threaddump.txt | sed -n l
==========================
                at org/springframework/security/ui/SpringSecurityFilt\
er.doFilter(SpringSecurityFilter.java:53)XX          X$
                at org/springframework/security/util/FilterChainProxy\
$VirtualFilterChain.doFilter(FilterChainProxy.java:406)XX          X$
==========================

sed '$!N; s/\n/X/g; s/$/X/mg;' threaddump.txt | sed -n l
==========================
                at org/springframework/security/ui/SpringSecurityFilt\
er.doFilter(SpringSecurityFilter.java:53)X          X$
                at org/springframework/security/util/FilterChainProxy\
$VirtualFilterChain.doFilter(FilterChainProxy.java:406)X          X$
==========================

Regards,
Gabriel Czernikier