我有以下示例文件(a),我想使用Unix或Python命令将其转换为示例文件(b)。我的实际文件要大得多(几GB)。你知道吗
(一):
Sol_00000001 H2O2 KNMO4 NaCl
Sol_00000002 NaCl NaCl
Sol_00000003 KOCl NHO2 NHO2
Sol_00000004 H2O2
Sol_00000005 KNMO4
Sol_00000006 NaCl
Sol_00000007 KOCl
Sol_00000008 NHO2
Sol_00000009 H2O2 NaCl KOCl NHO2 KNMO4
(b):
NaCl Sol_00000001 Sol_00000002 Sol_00000006 Sol_00000009
KOCl Sol_00000003 Sol_00000007 Sol_00000009
H2O2 Sol_00000001 Sol_00000004 Sol_00000009
NHO2 Sol_00000003 Sol_00000008 Sol_00000009
KNMO4 Sol_00000001 Sol_00000005 Sol_00000009
有人能帮忙吗?你知道吗
如果源数据是ch_源.txt,此脚本将创建_dst.txt文件以上面的格式。但在这个过程中会占用大量内存,因为在创建输出文件之前,必须存储所有数据。你知道吗
这是一个python2脚本。为了节省空间,python3脚本必须使用字节,并且将使用
items
而不是iteritems
。你知道吗通过进一步研究,您将了解如何在命令行上传递文件名,而不是将它们硬编码到脚本中。你知道吗
我将提供3种解决方案—Awk、Perl和python2。你知道吗
Awk
这是一个运行
awk
的shell脚本:Perl
Python2
示例输出
awk
不尝试对键进行排序。将输出通过管道传输到sort -f
以获得与Perl和Python相同的不区分大小写的排序输出是可行的。你知道吗基本上,你需要读取文件中的每一行,把每一行拆分成它的组成词,然后为每个分子记录它在什么溶液中出现。在python中,存储这些信息的最自然的数据结构是dict,键是分子,值是包含分子的解决方案列表。一旦构建了dict,就只需将每个条目写入一个文件。你知道吗
这应该足够让你开始了。试一试,如果你不能让它发挥作用,就带着具体的问题回来。你知道吗
相关问题 更多 >
编程相关推荐