snipt

Ctrl+h for KB shortcuts

reStructuredText

sed replace newline

1
2
3
4
5
6
7
sed ':a;N;$!ba;s/\n/ /g'

from Zsolt Botykai on Stack overflow
1. create a register via :a
2. append the current and next line to the register via N
3. if we are before the last line, branch to the created register $!ba (`$! means not to do it on the last line (as there should be one final newline)).
4. finally the substitution replaces every newline with a space on the pattern space (which is the contents of the a register = the whole file.
https://snipt.net/embed/6bd52988f141491bd5ccf11da28520fb/
/raw/6bd52988f141491bd5ccf11da28520fb/
6bd52988f141491bd5ccf11da28520fb
rst
reStructuredText
7
2019-07-21T17:38:52
True
False
False
/api/public/snipt/20880/
sed-replace-newline
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>sed &#39;:a;N;$!ba;s/\n/ /g&#39; </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>from Zsolt Botykai on Stack overflow </span><span id="L-4"><a name="L-4"></a><span class="m">1.</span> create a register via :a </span><span id="L-5"><a name="L-5"></a><span class="m">2.</span> append the current and next line to the register via N </span><span id="L-6"><a name="L-6"></a><span class="m">3.</span> if we are before the last line, branch to the created register $!ba (`$! means not to do it on the last line (as there should be one final newline)). </span><span id="L-7"><a name="L-7"></a><span class="m">4.</span> finally the substitution replaces every newline with a space on the pattern space (which is the contents of the a register = the whole file. </span></pre></div> </td></tr></table>
newline, replace, sed

Bash

remove newline chars in vi

1
2
3
:%s/^v<Carriage Return>//g

*hit the ctrl key + v then hit the carriage return.
https://snipt.net/embed/93b41e5ce27ed4ee81eb0f59144c7974/
/raw/93b41e5ce27ed4ee81eb0f59144c7974/
93b41e5ce27ed4ee81eb0f59144c7974
bash
Bash
3
2019-07-19T11:19:29
True
False
False
/api/public/snipt/10600/
remove-newline-chars-in-vi
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>:%s/^v&lt;Carriage Return&gt;//g </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>*hit the ctrl key + v <span class="k">then</span> hit the carriage <span class="k">return</span>. </span></pre></div> </td></tr></table>
linux, newline, vi

ActionScript

xml new line problem solution

1
2
3
4
function fixXMLNewLines(str:String):String{
    var new_str:String = str.split("\\n").join("\n");
    return new_str;
}
https://snipt.net/embed/da4ebdadec6bb8c3ea2c980fd1244cf5/
/raw/da4ebdadec6bb8c3ea2c980fd1244cf5/
da4ebdadec6bb8c3ea2c980fd1244cf5
as
ActionScript
5
2019-07-18T15:32:04
True
False
False
/api/public/snipt/802/
xml-new-line-problem-solution
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">fixXMLNewLines</span><span class="p">(</span><span class="nx">str</span><span class="o">:</span><span class="nb">String</span><span class="p">)</span><span class="o">:</span><span class="nb">String</span><span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">var</span> <span class="nx">new_str</span><span class="o">:</span><span class="nb">String</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s2">&quot;\\n&quot;</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s2">&quot;\n&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="nx">new_str</span><span class="o">;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
as2, flash, newline, xml

Bash

add newlines to one-line xml string

sed 's/\(<\/[a-zA-Z0-9]*>\)/\1\
/g'
https://snipt.net/embed/ef54209ac6189b5143e415f98ea033e0/
/raw/ef54209ac6189b5143e415f98ea033e0/
ef54209ac6189b5143e415f98ea033e0
bash
Bash
2
2019-07-18T23:06:45
True
False
False
/api/public/snipt/217/
add-newlines-to-one-line-xml-string
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>sed <span class="s1">&#39;s/\(&lt;\/[a-zA-Z0-9]*&gt;\)/\1\</span> </span><span id="L-2"><a name="L-2"></a><span class="s1">/g&#39;</span> </span></pre></div> </td></tr></table>
bash, newline, sed, xml