如何在ruby中安排我的数据

时间:2017-06-09 11:03:10

标签: ruby

如果我的问题非常明显,我真诚地道歉。我正在打破它,但却得到一个可行的解决方案或逻辑。

下面的输入文件(input.txt)

Record: C:/my_files/00_Roll_Tom-values.txt

#RakeBoss-Random as on 12/19/2016
[groups]
met = chk\rel_io_chk, chk\dev_op_io,
div = chk\kzhr2x, chk\zz52t0, chk\czzjrt
rakeonly = chk\rzgnsd, chk\cztw5h

[/]
@met = rw
@div = rw
@rakeonly = r
*******************************************************************************************
Record: C:/my_files/Rander-values.txt

#RakeBoss-Jan 21st QA
[groups]
met = chk\rel_io_chk, chk\dev_op_io
div = chk\541kmj, chk\zz52t0
app_only = chk\zz9ycd
check_io = chk\wder4, chk\zz9ycd
div_write = chk\lo98j3
year_on = chk\3w345f
[/]
@met = rw
@div = rw
@app_only= r
@check_io = r
@div_write = rw
@year_on = r

[/wedmin]
@check_io = rw
div_write= rw

[/doc/prod]
@div = rw
@app_only = r
year_on = rw
*******************************************************************************************
Record: C:/my_files/456_Milo_123-values.txt

#RakeBoss-Jan 21st Prod
[groups]
met = chk\rel_io_chk, chk\dev_op_io
div = chk\kzhr2x, chk\zz52t0, chk\czzjrt, chk\pzjwr3
jee_only = chk\zz9ycd, chk\hz659l, chk\zzktgj, 
check_io = chk\8u7y01, chk\zz9ycd
unique_key = chk\zz9ycd
year_on = chk\dytg6
[/]
@met = rw
@div = rw
@rakeonly = r

[/Release]
@check_io = rw
@unique_key = rw

[/Redmine/Treehub]
@div = r
@jee_only = rw
******************************************************************************************
Record: C:/my_files/Docker_red-values.txt

#RakeBoss-Check it io.
[groups]
met = chk\rel_io_chk, chk\dev_op_io, chk\njk987
div = chk\gzlqvg, chk\zzkgyp, chk\lzg0rp, chk\gzp2kv
rakeonly = chk\qzvjq0, chk\kz6w6t, chk\bzy4kj, chk\dzfbhp

[/]
@met = rw
@div = rw
@rakeonly = r
******************************************************************************************

我正在尝试读取输入文件并将格式化的输出写入Excel。每个模块或一组由'#'系列分隔。对于第一组,如下所示,输出应采用以下格式

第1集

Record: C:/my_files/00_Roll_Tom-values.txt

#RakeBoss-Random as on 12/19/2016
[groups]
met = chk\rel_io_chk, chk\dev_op_io,
div = chk\kzhr2x, chk\zz52t0, chk\czzjrt
rakeonly = chk\rzgnsd, chk\cztw5h

[/]
@met = rw
@div = rw
@rakeonly = r

excel中的输出应为

file_name   cluster       id                   case     access_levels

00_Roll_Tom   met        chk\rel_io_chk          /       rw
00_Roll_Tom   met        chk\dev_op_io           /       rw
00_Roll_Tom   div        chk\kzhr2x              /       rw
00_Roll_Tom   div        chk\zz52t0              /       rw
00_Roll_Tom   div        chk\czzjrt              /       rw
00_Roll_Tom   rakeonly   chk\rzgnsd              /       r  
00_Roll_Tom   rakeonly   chk\cztw5h              /       r      

第二组

Record: C:/my_files/Rander-values.txt

#RakeBoss-Jan 21st QA
[groups]
met = chk\rel_io_chk, chk\dev_op_io
div = chk\541kmj, chk\zz52t0
check_io = chk\wder4, chk\zz9ycd
div_write = chk\lo98j3

[/]
@met = rw
@div = rw
@check_io = r
@div_write = r

[/wedmin]
@check_io = rw
div_write= rw

[/doc/prod]
@div = r

输出的格式应与第1套的格式相同,其余部分的输出格式相同。

Rander-values   met       chk\rel_io_chk   /            r
Rander-values   met       chk\dev_op_io    /            r
Rander-values   div       chk\541kmj       /            r
Rander-values   div       chk\zz52t0       /            r
Rander-values   check_io  chk\wder4        /            r
Rander-values   check_io  chk\zz9ycd       /            r
Rander-values   div_write lo98j3           /            r
Rander-values   check_io  chk\wder4        /wedmin      rw
Rander-values   check_io  chk\zz9ycd       /wedmin      rw
Rander-values   div_write lo98j3           /wedmin      rw
Rander-values   div       chk\541kmj       /doc/prod    r
Rander-values   div       chk\zz52t0       /doc/prod    r

我不确定如何处理数据或我应该考虑哪种结构。我已经通过多个文档和博客,但我无法修复一个。这里的任何帮助都非常感谢。感谢。

我只是坚持使用下面的代码,我迷失了如何前进

file = File.open("C:/input.txt", "r").read
data = file.split(/\*+/)

0 个答案:

没有答案