If your data is always set up such that the first line has a row of
data and the second has additional data, you can set up a variable
outside the eachLine(), then if the line number is even (because it's
zero-based) you store the line and if it is odd you append it to the
previous line and output it:
def myLine = ''
reader.eachLine {line, lineNum ->
if(lineNum % 2 == 0) {
myLine = line
} else {
writer << (myLine + line + '\n')
}
}
Please let me know if I've misunderstood your question.
Regards,
Matt
On Wed, Aug 16, 2017 at 9:06 AM, prabhu Mahendran
<[email protected]> wrote:
> my data is in form of unstructured data in which having end of column stored
> in two rows like below.
>
> UID|Name|ID|Mail
> 1|Ester|991|sd
> gmail
> 2|Siva|992|siva
> hotmail
> 3|Hari|993|hi gmail
>
> Some rows in data has been fulfilled but some rows to avoid those two line
> data into single line like below.
>
> UID|Name|ID|Mail
> 1|Ester|991|sd gmail
> 2|Siva|992|siva hotmail
> 3|Hari|993|hi gmail
> I don't know that nifi processors in which helpful for this conversion.
>
> But i have tried following Groovy Script to read lines and not able to find
> way to combine spitted rows into single row.
>
> def flowfile = session.get()
> if(!flowfile)return
> flowfile = session.write(flowfile, {rawIn, rawOut->
> // ## transform streams into reader and writer
> rawIn.withReader("UTF-8"){reader->
> rawOut.withWriter("UTF-8"){writer->
> reader.eachLine{line, lineNum->
> if(!line.isEmpty())
> {// ## let use regular expression to transform each line
> writer << line << '\n'
> }
> }
> }
> }
> } as StreamCallback)
> session.transfer(flowfile, REL_SUCCESS)
>
> Can anyone suggest me idea convert my data into requirement?