我创建了带有值的csv文件。我能够读取行,但不知道如何访问列的各个值。
require "csv"
CSV.open("file.csv", "w")
do |csv|
csv << ["val1", "val2","mul"]
csv << ["53", "27"]
csv<<["32","20"]
end
答案 0 :(得分:1)
如果你有一个标题行,你可能需要忽略标题行。但总的想法是:
CSV.open('dest.csv', 'w') do |csv|
csv << ["val1", "val2", "mul"]
CSV.foreach('source.csv', headers: true) do |row|
c1 = row['val1']
c2 = row['val2']
csv << [c1, c2, c1*c2]
end
end
如果你有标题,你可以这样做:
awk -F "," '{print $1,$2,$1*$2}' source.csv > dest.csv
您也可以使用下面的方法来获取非红宝石解决方案:
job('Sample_dev')
{
steps{
singleConditionalBuilder{
condition{
alwaysRun()
}
buildStep {
maven{
targets('install')
name('')
pom('')
properties('')
jvmOptions('')
usePrivateRepository(false)
settings {
standard()
}
globalSettings {
standard()
}
injectBuildVariables(false)
}
}
runner {
fail()
}
}
}
}