Groovy web console

subscribe to the feed Subscribe
to this
site

CSV Fix

Published 5 months ago by Bais with tags csv fix pipeline polymorph
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
testo = '''
EXTRACT|2022-06-30|0||11
EXTRACT123|2022-06-30|0||11
456|2022-06-30|0||11|hhh|2022-06-30|0||11
''';



    def newbody = ""
    def maxCount = 0
    
    testo.readLines().each {
        if (it.count("|") > maxCount) {
            maxCount = it.count("|")
            println(maxCount)
        }
    }
    
    testo.readLines().each {
        empty = ''
        print("String length:")
        println(it.length())
        println(it.count("|"))

        if (it.count("|") < maxCount && it.length() > 0){
            for (i = 0; i <= it.count("|")+1; i++) {
                empty = empty + '|'
            }
            result = it+empty
            newbody = newbody+result+"\r\n"
        } else {
            newbody = newbody+it+"\r\n";
        }
    }

println("Result:")
println(maxCount)
println(newbody.count("|"))
println(newbody )