How to get the next 15 line after the date with groovy script
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 !
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I can't show the file but it's a log file with something like :
Then for each part that I got for example the same date, I want to write the next 15 line (which represent my webservice) in another file
13/03/2019 15:24:48.424 [http-thread-pool-8080(18)]
<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Header>
<OS_Header xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="os.xsd.v1" xsi:nil="true"/>
</wsse:UsernameToken>
</wsse:Security>
</S:Header>
<S:Body>
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The sample you've provided is just the soap wrapper (and so everybody's soap wrapper looks pretty much the same!) and doesn't really provide @rao the detail he probably needs to answer this. If he's asking for sample content, he'd need the structure of the xml payload contained within the soapbody tag....which is the bit you haven't included!
Cheers,
richie
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
But yes, it's indeed the same and that's why I put it. 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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any ways, the above approach does not seem to be correct.
And the log files roll away to different files based on file size that is configured.
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 !
