mirror of
https://github.com/jaywcjlove/reference.git
synced 2025-06-19 21:51:20 +08:00
feat: add autolink headings. 617a46c1a5
This commit is contained in:
@ -15,9 +15,9 @@
|
||||
<path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="currentColor"></path>
|
||||
<path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="currentColor"></path>
|
||||
</svg>
|
||||
<span class="title">Quick Reference</span></a><div class="menu"><a href="https://github.com/jaywcjlove/reference/blob/main/docs/sed.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap max-container"><header class="wrap-header h1wrap"><h1>Sed 备忘清单</h1><div class="wrap-body">
|
||||
</div></header><div class="h1wrap-body"><div class="wrap"><div class="wrap-header h2wrap"><h2>入门</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap"><div class="wrap-header h3wrap"><h3>Sed 用法</h3><div class="wrap-body">
|
||||
<span class="title">Quick Reference</span></a><div class="menu"><a href="https://github.com/jaywcjlove/reference/blob/main/docs/sed.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap max-container"><header class="wrap-header h1wrap"><h1 id="sed-备忘清单"><a aria-hidden="true" tabindex="-1" href="#sed-备忘清单"><span class="icon icon-link"></span></a>Sed 备忘清单</h1><div class="wrap-body">
|
||||
</div></header><div class="h1wrap-body"><div class="wrap"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap"><div class="wrap-header h3wrap"><h3 id="sed-用法"><a aria-hidden="true" tabindex="-1" href="#sed-用法"><span class="icon icon-link"></span></a>Sed 用法</h3><div class="wrap-body">
|
||||
<p>语法</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token punctuation">[</span>options<span class="token punctuation">]</span> <span class="token builtin class-name">command</span> <span class="token punctuation">[</span>input-file<span class="token punctuation">]</span>
|
||||
</span></code></pre>
|
||||
@ -26,7 +26,7 @@
|
||||
</span></code></pre>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token builtin class-name">echo</span> <span class="token string">'123abc'</span> <span class="token operator">|</span> <span class="token function">sed</span> <span class="token string">'s/[0-9]+//g'</span>
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3>选项示例</h3><div class="wrap-body"><!--rehype:wrap-class=col-span-2-->
|
||||
</div></div></div><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3 id="选项示例"><a aria-hidden="true" tabindex="-1" href="#选项示例"><span class="icon icon-link"></span></a>选项示例</h3><div class="wrap-body"><!--rehype:wrap-class=col-span-2-->
|
||||
<table class="show-header">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -63,26 +63,26 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><!--rehype:className=show-header-->
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>多个命令</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="多个命令"><a aria-hidden="true" tabindex="-1" href="#多个命令"><span class="icon icon-link"></span></a>多个命令</h3><div class="wrap-body">
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token builtin class-name">echo</span> <span class="token string">"hello world"</span> <span class="token operator">|</span> <span class="token function">sed</span> <span class="token parameter variable">-e</span> <span class="token string">'s/h/H/g'</span> <span class="token parameter variable">-e</span> <span class="token string">'s/w/W/g'</span>
|
||||
</span><span class="code-line line-number" line="2">Hello World
|
||||
</span></code></pre>
|
||||
<p>使用 <code>-e</code> 执行多个 sed 命令</p>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>Sed 脚本</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="sed-脚本"><a aria-hidden="true" tabindex="-1" href="#sed-脚本"><span class="icon icon-link"></span></a>Sed 脚本</h3><div class="wrap-body">
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token builtin class-name">echo</span> <span class="token string">'s/h/H/g'</span> <span class="token operator">>></span> hello.sed
|
||||
</span><span class="code-line line-number" line="2">$ <span class="token builtin class-name">echo</span> <span class="token string">'s/w/W/g'</span> <span class="token operator">>></span> hello.sed
|
||||
</span><span class="code-line line-number" line="3">$ <span class="token builtin class-name">echo</span> <span class="token string">"hello world"</span> <span class="token operator">|</span> <span class="token function">sed</span> <span class="token parameter variable">-f</span> hello.sed
|
||||
</span><span class="code-line line-number" line="4">Hello World
|
||||
</span></code></pre>
|
||||
<p>使用 <code>-f</code> 执行 sed 脚本文件</p>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>Examples</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="examples"><a aria-hidden="true" tabindex="-1" href="#examples"><span class="icon icon-link"></span></a>Examples</h3><div class="wrap-body">
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'s/old/new/g'</span> file.txt
|
||||
</span><span class="code-line line-number" line="2">$ <span class="token function">sed</span> <span class="token string">'s/old/new/g'</span> file.txt <span class="token operator">></span> new.txt
|
||||
</span><span class="code-line line-number" line="3">$ <span class="token function">sed</span> <span class="token string">'s/old/new/g'</span> <span class="token parameter variable">-i</span> file.txt
|
||||
</span><span class="code-line line-number" line="4">$ <span class="token function">sed</span> <span class="token string">'s/old/new/g'</span> <span class="token parameter variable">-i.backup</span> file.txt
|
||||
</span></code></pre>
|
||||
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2>Sed 命令</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3>命令</h3><div class="wrap-body"><!--rehype:wrap-class=col-span-2-->
|
||||
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2 id="sed-命令"><a aria-hidden="true" tabindex="-1" href="#sed-命令"><span class="icon icon-link"></span></a>Sed 命令</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3 id="命令"><a aria-hidden="true" tabindex="-1" href="#命令"><span class="icon icon-link"></span></a>命令</h3><div class="wrap-body"><!--rehype:wrap-class=col-span-2-->
|
||||
<table class="show-header">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -124,7 +124,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table><!--rehype:className=show-header-->
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>空间命令</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="空间命令"><a aria-hidden="true" tabindex="-1" href="#空间命令"><span class="icon icon-link"></span></a>空间命令</h3><div class="wrap-body">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@ -159,7 +159,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>Flags</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="flags"><a aria-hidden="true" tabindex="-1" href="#flags"><span class="icon icon-link"></span></a>Flags</h3><div class="wrap-body">
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'s/old/new/[flags]'</span> <span class="token punctuation">[</span>input-file<span class="token punctuation">]</span>
|
||||
</span></code></pre>
|
||||
<hr>
|
||||
@ -197,7 +197,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>循环命令</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="循环命令"><a aria-hidden="true" tabindex="-1" href="#循环命令"><span class="icon icon-link"></span></a>循环命令</h3><div class="wrap-body">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@ -232,7 +232,7 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>杂项标志</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="杂项标志"><a aria-hidden="true" tabindex="-1" href="#杂项标志"><span class="icon icon-link"></span></a>杂项标志</h3><div class="wrap-body">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@ -255,8 +255,8 @@
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2>Sed 示例</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap row-span-2"><div class="wrap-header h3wrap"><h3>替换文本</h3><div class="wrap-body"><!--rehype:wrap-class=row-span-2-->
|
||||
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2 id="sed-示例"><a aria-hidden="true" tabindex="-1" href="#sed-示例"><span class="icon icon-link"></span></a>Sed 示例</h2><div class="wrap-body">
|
||||
</div></div><div class="h2wrap-body"><div class="wrap row-span-2"><div class="wrap-header h3wrap"><h3 id="替换文本"><a aria-hidden="true" tabindex="-1" href="#替换文本"><span class="icon icon-link"></span></a>替换文本</h3><div class="wrap-body"><!--rehype:wrap-class=row-span-2-->
|
||||
<p>替换所有出现的字符串</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'s/old/new/g'</span> file.txt
|
||||
</span></code></pre>
|
||||
@ -278,7 +278,7 @@
|
||||
<p>删除评论。 即使是那些在行尾的</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'s/#.*$//'</span> file.txt
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>搜索文本</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="搜索文本"><a aria-hidden="true" tabindex="-1" href="#搜索文本"><span class="icon icon-link"></span></a>搜索文本</h3><div class="wrap-body">
|
||||
<p>搜索字符串并仅打印匹配的行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token parameter variable">-n</span> <span class="token string">'/hello/p'</span> file.txt
|
||||
</span></code></pre>
|
||||
@ -288,7 +288,7 @@
|
||||
<p>搜索字符串,但仅输出不匹配的行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token parameter variable">-n</span> <span class="token string">'/hello/!p'</span> file.txt
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>追加行</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="追加行"><a aria-hidden="true" tabindex="-1" href="#追加行"><span class="icon icon-link"></span></a>追加行</h3><div class="wrap-body">
|
||||
<p>在第 2 行之后追加一行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'2a Text after line 2'</span> file.txt
|
||||
</span></code></pre>
|
||||
@ -298,7 +298,7 @@
|
||||
<p>从第 3 行开始,每 3 行后追加一行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'3~3a Some text'</span> file.txt
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3>编号</h3><div class="wrap-body"><!--rehype:wrap-class=col-span-2-->
|
||||
</div></div></div><div class="wrap col-span-2"><div class="wrap-header h3wrap"><h3 id="编号"><a aria-hidden="true" tabindex="-1" href="#编号"><span class="icon icon-link"></span></a>编号</h3><div class="wrap-body"><!--rehype:wrap-class=col-span-2-->
|
||||
<p>文件的数字行(简单的左对齐)</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token operator">=</span> file.txt <span class="token operator">|</span> <span class="token function">sed</span> <span class="token string">'N;s/\n/\t/'</span>
|
||||
</span></code></pre>
|
||||
@ -311,14 +311,14 @@
|
||||
<p>计算行数(模拟“wc -l”)</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token parameter variable">-n</span> <span class="token string">'$='</span>
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>前置行</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="前置行"><a aria-hidden="true" tabindex="-1" href="#前置行"><span class="icon icon-link"></span></a>前置行</h3><div class="wrap-body">
|
||||
<p>在第 5 行之前插入文本</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'5i line number five'</span> file.txt
|
||||
</span></code></pre>
|
||||
<p>在包含“hello”的每一行之前插入“示例:”</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'/hello/i Example: '</span> file.txt
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>删除行</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="删除行"><a aria-hidden="true" tabindex="-1" href="#删除行"><span class="icon icon-link"></span></a>删除行</h3><div class="wrap-body">
|
||||
<p>删除文件中的第 5-7 行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'5,7d'</span> file.txt
|
||||
</span></code></pre>
|
||||
@ -337,7 +337,7 @@
|
||||
<p>删除以“#”开头的行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'/^#/d'</span> file.txt
|
||||
</span></code></pre>
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3>文件间距</h3><div class="wrap-body">
|
||||
</div></div></div><div class="wrap"><div class="wrap-header h3wrap"><h3 id="文件间距"><a aria-hidden="true" tabindex="-1" href="#文件间距"><span class="icon icon-link"></span></a>文件间距</h3><div class="wrap-body">
|
||||
<p>双倍行距</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> G
|
||||
</span></code></pre>
|
||||
@ -359,7 +359,7 @@
|
||||
<p>在匹配“正则表达式”的行周围插入一个空行</p>
|
||||
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line line-number" line="1">$ <span class="token function">sed</span> <span class="token string">'/regex/{x;p;x;G;}'</span>
|
||||
</span></code></pre>
|
||||
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2>另见</h2><div class="wrap-body">
|
||||
</div></div></div></div></div><div class="wrap"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
|
||||
<ul>
|
||||
<li><a href="https://gist.github.com/ssstonebraker/6140154">sed 备忘单</a> <em>(gist.github.com)</em></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user