I have the data in a text (.txt) file and not in CSV. Each line is a long JSON message. I need to read the file line by line and pass it to JSON body of my REST API message. I tried using a JDBC pre-processor using Groovy but it gets only ne line. Any help would be appreciated.
In my HTTP request (only line of code is: ${extractedLine} ), I am trying to send the messages extracted from my text file one by one (for every line extracted from a the .txt file, one request will be submitted) via JSR223 pre-processor with the following code.
java.io.File
// Replace with the actual path to your text file
def filePath = "/path/to/your/file.txt"
// Specify the line number to read (starting from 1)
def lineNumber = 1
def file = new File(filePath)
def lines = file.readLines()
if (lineNumber <= lines.size()) {
def lineContent = lines[lineNumber - 1]
vars.put("extractedLine", lineContent)
} else {
log.warn("Line number $lineNumber is out of bounds. File contains ${lines.size()} lines.")
}
But it is retrieving only line#1 because I defined it as 1. How do I increase it for every request? Thanks