Groovy web console

subscribe to the feed Subscribe
to this
site

Fill CSV missing delimiters multyline

Published 5 months ago by Bais with tags cpi csv
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
testo = '''EXTRACT|2022-06-30|0||11
EXTRACT|2022-06-30|0||11
EXTRACT|2022-06-30|0||11EXTRACT|2022-06-30|0||11EXTRACT|2022-06-30|0||11EXTRACT|2022-06-30|0||11
EXTRACT|2022-06-30|0||11EXTRACT|2022-06-30|0||11EXTRACT|2022-06-30|0||11
'''.stripMargin('    ').stripIndent()


numero_campi = 10

testo.readLines().each {
empty = ''

if (it.count("|") <= numero_campi){
print(it + " ")
   for (i = 0; i <= it.count("|")+1; i++) { 
        empty = empty + '|' 
   } 

result = it+empty
 
println(it.count("|"))
println(it+empty)
println(result.count("|"))
} else {
      println("trash: " + it.count("|"))
}
}