In my text file I will have user data on each line. I’m using the In Lines with Cut at 1 limits.
At the end of all records comes a line with the SUPX tag, which can contain from 1 to 90 lines, however it would need to maintain its formatting according to the text view, but it ends up being “broken” in each line, how can I define that when you reach this tag the definition of limits is changed?
I’m sorry, but I have the feeling that your forum post is missing some information.
Where are you using the, and I quote, “In Lines with Cut at 1 limits”? I assume that you are referring to the text file input data setting Cut on number of lines*?
but it ends up being “broken” in each line
Where does it ends up being broken? In the Text viewer pane of the Designer application? When writing to a text file by a script from within a DataMapper configuration?
Yeah, “cut on number of lines” , so that each line displays only one record, as I advance through the records. However, when reaching line 3, for example, I wanted to change the emulation so that it encompassed all the text from line 3 until the end. But in this “Cut on… 1” mode, each line below 3 ends up being stored in 1 record.
I ended up solving it by adapting a pre-processing script that Phil had helped me with, so that it would insert blank lines for all records until they all had 90 lines, which would be the maximum size of a possible record.
var inFile = openTextReader(data.filename, "Windows-1252");
var outFile = openTextWriter(data.filename + ".tmp", "Windows-1252");
var inRecord = false;
var maxLines = 90;
var lineCount = 0;
var newRecord = "1$NEW$";
var endText = "!! END OF JES";
var line = null;
var firstLineProcessed = false;
// Processa o arquivo original e escreve o conteúdo no arquivo temporário
while ((line = inFile.readLine()) != null) {
if (line.startsWith(newRecord)) {
if (inRecord) {
for (var i = maxLines - lineCount; i > 0; i--) {
outFile.write("\n");
}
}
lineCount = 0;
inRecord = true;
} else if (line.includes(endText)) {
// Remove a linha que contém "!! END OF JES"
continue;
}
outFile.write(line + "\n");
lineCount++;
}
// Adiciona linhas em branco após o último bloco, se necessário
if (inRecord) {
for (var i = maxLines - lineCount; i > 0; i--) {
outFile.write("\n");
}
}
outFile.close();
inFile.close();
// Substitui o arquivo original pelo arquivo temporário
deleteFile(data.filename);
copyFile(data.filename + ".tmp", data.filename);