J
Junhui Liao
Dear all,
My script tried to read from one original tsv file and distribute into
new multiple tsv files.
Each line of the original file is like this: time_1, signal_1, time_2,
signal_2... time_4096, signal_4096.
I would like to write them into file_1, file_2, ... file_4096
accordingly, and these files contain time_1, signal_1; time_2, signal_2;
... time_4096, signal_4096 separately.
My script did well only if the original file contains ONE line.
If the original file has two or more lines, the error message like
following,
new_split.rb:17: undefined method `+' for nil:NilClass (NoMethodError)
By tracing the output, I found it seemed the script just read ONE line,
since the put results like this :
........(omitted a lots of lines here)
8182
"4.08963252844486E+00"
"-2.3E-03"
8184
"4.09063219413236E+00"
"-3.1E-03"
8186
"4.09163185987611E+00"
"-7E-04"
8188
"4.09263152560423E+00"
"-3.7E-03"
8190
"4.09363119136048E+00"
"3.6E-03"
8192
nil
nil
And my script is like this:
@a = []
@itemnum = 4096
@counter = 0
@linenum = 10
File.open("../original_data/test_2lines.tsv").each_line
do |record| # "^M"
#File.open("../original_data/one_line.tsv").each_line do
|record|
@a = record.chomp.split("\t")
@itemnum.times do |n|
File.open("#{n}_debug_split"+".tsv" , "w") do |f|
puts @counter
puts @a[@counter].inspect + "\n"
puts @a[@counter+1].inspect + "\n"
f << @a[@counter] + "\t" + @a[@counter+1] + "\n"
@counter += 2
end
end
end
Thanks a lot for your comments in advance !
Junhui
BTW, at the end of each line in original tsv file, this is a "^M"
appended.
I don't know how it comes and results something or not.
My script tried to read from one original tsv file and distribute into
new multiple tsv files.
Each line of the original file is like this: time_1, signal_1, time_2,
signal_2... time_4096, signal_4096.
I would like to write them into file_1, file_2, ... file_4096
accordingly, and these files contain time_1, signal_1; time_2, signal_2;
... time_4096, signal_4096 separately.
My script did well only if the original file contains ONE line.
If the original file has two or more lines, the error message like
following,
new_split.rb:17: undefined method `+' for nil:NilClass (NoMethodError)
By tracing the output, I found it seemed the script just read ONE line,
since the put results like this :
........(omitted a lots of lines here)
8182
"4.08963252844486E+00"
"-2.3E-03"
8184
"4.09063219413236E+00"
"-3.1E-03"
8186
"4.09163185987611E+00"
"-7E-04"
8188
"4.09263152560423E+00"
"-3.7E-03"
8190
"4.09363119136048E+00"
"3.6E-03"
8192
nil
nil
And my script is like this:
@a = []
@itemnum = 4096
@counter = 0
@linenum = 10
File.open("../original_data/test_2lines.tsv").each_line
do |record| # "^M"
#File.open("../original_data/one_line.tsv").each_line do
|record|
@a = record.chomp.split("\t")
@itemnum.times do |n|
File.open("#{n}_debug_split"+".tsv" , "w") do |f|
puts @counter
puts @a[@counter].inspect + "\n"
puts @a[@counter+1].inspect + "\n"
f << @a[@counter] + "\t" + @a[@counter+1] + "\n"
@counter += 2
end
end
end
Thanks a lot for your comments in advance !
Junhui
BTW, at the end of each line in original tsv file, this is a "^M"
appended.
I don't know how it comes and results something or not.