LucN
6 years agoOccasional Contributor
How to get the next 15 line after the date with groovy script
Hello eveyrone, I have another problem,
I'm trying to get a number of line after a specific date is found in my file. for example, if I found the date in my File, I would like to write, in another file the 15 lines after it. I start to write something such as :
resultFile.withWriter{ writer -> readFile.withReader{ reader -> while (line = reader.readLine()) { if(line.startsWith(dateRequest)){ writer << "${line}" << System.properties.'line.separator' } } } }
But I don't know how to add the next 15 line each time ?
What's important for me here is the date before the soap service. What I want to do is :
- for each date when a soap service is send
- write the 15 line after this date in another file
- Do it again for other soap serice with the same date
Also, the thing is that it's log file which is used by a lot of people so a lot of saop service are not from me and it's not possible to differenciate them expect with the date
Do you know how ? Thanx in advance !
I'll anwser myslef since I solved it :
writeFile.withWriter { writer -> // read the file using a reader readFile.withReader{ reader -> while (line = reader.readLine()) { // if line starts with your comment "'" if(line.contains(threadInfo)){ def lineCount = 0 while(lineCount < lineCountMax) { def nextLine = reader.readLine() // to the current line, and writeit in the result file writer << "${nextLine}" << System.properties.'line.separator' lineCount ++; } } } } }
thx anyaway !