将大型文本文件重新格式化为一行字符串(通过 BASH)
File1:
hello
- dictionary definitions:
hi
hello
hallo
greetings
salutations
no more hello for you
-
world
- dictionary definitions:
universe
everything
the globe
the biggest tree
planet
cess pool of organic life
-
我需要将其(对于大量单词)格式化为术语定义格式(每个术语一行)。如何才能实现这一目标呢?没有一个单词是相同的,只有上面看到的结构是相同的。结果文件看起来像这样:
hello - dictionary definitions: hi hello hallo greetings salutations no more hello for you -
world - dictionary definitions: universe everything the globe the biggest tree planet cess pool of organic life -
Awk/Sed/Grep/Cat 是常见的竞争者。
File1:
hello
- dictionary definitions:
hi
hello
hallo
greetings
salutations
no more hello for you
-
world
- dictionary definitions:
universe
everything
the globe
the biggest tree
planet
cess pool of organic life
-
I need to format this (for a huge list of words) into a term to definition format (one line per term). How can one achieve this? None of the words are the same, only the structure seen above is. The resultant file would look something like this:
hello - dictionary definitions: hi hello hallo greetings salutations no more hello for you -
world - dictionary definitions: universe everything the globe the biggest tree planet cess pool of organic life -
Awk/Sed/Grep/Cat are the usual contenders.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
谁说只有 Perl 才能优雅地做到这一点? :)
或者
and who says only Perl can do it elegantly ? :)
OR
输出:
outputs:
Perl 一行:
给出
This is 'some like' your required output.
A perl one-liner:
gives
This is 'something like' your required output.
不确定您将使用的脚本语言,这里是伪代码:
Not sure the scripting language you will be using, pseudo code here:
尝试一下这个班轮的工作条件是,一个单词总是 6 行
Try this one liner works on a conditions that theer will always be 6 lines for a word