Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想运行一个脚本来从 html 文件中提取一些字符串,并将所有字符串导入到一个新文件中。更具体地说,我想查看 all<td>和</td>pairs 之间的字符串,如果它们之间的字符串是 length k,则提取字符串。
<td>
</td>
k
awk不是解析 xml 的正确工具,但对于这种简单的情况,以下可能就足够了。
awk
awk '/<\/$/ && length == k + 2' RS='td>' k=$K input
这将输出每个字符串加上结尾的</. 这是一种 hack,不应被视为可靠、强大的解决方案。
</