可以用 shell 脚本实现这个功能吗?

2019-09-24 21:56:20 +08:00
 VKMEPR

服务器上有多个 yml 数据文件,想转换为 HTML 表格文件。原数据不是很复杂,有两列数据,具体如下:

yml 文件内容

date:
  1.0.1: http://example.com/1.0.1.tgz
  1.0.2: http://example.com/1.0.2.tgz
  1.0.3: http://example.com/1.0.3.tgz
  1.0.4: http://example.com/1.0.4.tgz
  1.0.5: http://example.com/1.0.5.tgz
  1.0.6: http://example.com/1.0.6.tgz
  1.0.7: http://example.com/1.0.7.tgz
  1.0.8: http://example.com/1.0.8.tgz
  1.0.9: http://example.com/1.0.9.tgz
  1.0.10: http://example.com/1.0.10.tgz

需要转换表格格式,有几个地方需要操作:1. 忽略第一行 date:字符串,2. 剩下的版本号和下载链接分两列,3. 网址添加超链接标签。

<table>
	<thead>
		<tr>
			<th>ver</th>
			<th>link</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>1.0.1</td>
			<td><a href="http://example.com/1.0.1.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.2</td>
			<td><a href="http://example.com/1.0.2.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.3</td>
			<td><a href="http://example.com/1.0.3.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.4</td>
			<td><a href="http://example.com/1.0.4.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.5</td>
			<td><a href="http://example.com/1.0.5.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.6</td>
			<td><a href="http://example.com/1.0.6.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.7</td>
			<td><a href="http://example.com/1.0.7.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.8</td>
			<td><a href="http://example.com/1.0.8.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.9</td>
			<td><a href="http://example.com/1.0.9.tgz">file</a></td>
		</tr>
		<tr>
			<td>1.0.10</td>
			<td><a href="http://example.com/1.0.10.tgz">file</a></td>
		</tr>
	</tbody>
</table>
4776 次点击
所在节点    Linux
27 条回复
oneisall8955
2019-09-25 06:43:19 +08:00
略简单,正则匹配,分 2 组完事了
Nitroethane
2019-09-25 07:37:26 +08:00
用 Python 解析出来后根据自己的需求拼接 markdown 字符串,然后渲染成 HTML
msg7086
2019-09-25 08:00:23 +08:00
想起我司傻逼代码用 shell 调 awk 解析 XML。
特别想打死那个写代码的人。
VKMEPR
2019-09-25 08:22:50 +08:00
@aheadlead 真心感谢!
VKMEPR
2019-09-25 08:23:34 +08:00
@ant2017 感谢大佬!
VKMEPR
2019-09-25 08:33:27 +08:00
@ChristopherWu 感谢建议!会结合大佬们给建议和示例去理解用法
OceanSea
2019-10-03 11:03:51 +08:00
vim 都可以 录制宏

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/603853

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX