如何从项目交替出现在每列中的列表中制作两列的 Markdown 表格?

Ann*_*lla 4 command-line text-processing markdown

我有一长串期刊标题中常见单词的缩写。在列表中,完整单词后面跟着其缩写。例如:

  • 行政
  • 行政。
  • 应用
  • 应用。
  • 行政的
  • 管理。
  • 近似
  • 大约。

我想将列表变成 Markdown 表,如下所示:

单词 缩写
行政 行政。
应用 应用。

问题是,手动完成此操作将花费很长时间。所以,我正在寻找一些方法来更快地做到这一点。如果有帮助的话,所有缩写形式都以句点 (.) 结尾。

我在网上查看过但找不到任何与此相关的内容。这就是我在这里问的原因。有什么帮助吗?

N0r*_*ert 5

假设我们有包含您问题中的列表的输入文件。我们可以使用以下命令填充它:

\n
cat <<EOF > words+abbrs.txt\nAdministration\nAdmin.\nApplied\nAppl.\nAdministrative\nAdminist.\nApproximate\nApprox.\nEOF\n
Run Code Online (Sandbox Code Playgroud)\n

在 Ubuntu 上可以使用简单的脚本创建 Markdown 表,如下所示:

\n
    \n
  • 愚蠢的一步步方法

    \n
    # write table header\necho "**Word** | **Abbreviation**" > table.md\necho "- | -" >> table.md\n\n# extract odd lines as words to file words.txt\nawk \'NR%2==1\' words+abbrs.txt > words.txt\n# extract even lines as abbreviations to file abbrs.txt\nawk \'NR%2==0\' words+abbrs.txt > abbrs.txt\n\n# combine columns from words.txt and abbrs.txt with \'|\' separator\npaste -d \'|\' words.txt abbrs.txt >> table.md\n
    Run Code Online (Sandbox Code Playgroud)\n
  • \n
  • 智能单行方法(感谢@steeldriver)

    \n
    { printf \'%s\\n\' \'**Word** | **Abbreviation**\' \'-|-\'; paste -d \'|\' - - < words+abbrs.txt; } > table.md\n
    Run Code Online (Sandbox Code Playgroud)\n
  • \n
\n

您将获得包含以下内容的 Markdown 文件:

\n
\n
$ cat table.md \n**Word** | **Abbreviation**\n- | -\nAdministration|Admin.\nApplied|Appl.\nAdministrative|Administ.\nApproximate|Approx.\n
Run Code Online (Sandbox Code Playgroud)\n
\n

所以它会被渲染为 HTML

\n
\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n
单词缩写
行政行政。
应用应用。
行政的管理。
近似大约。
\n
\n
\n

有关所用工具的更多信息:

\n\n