this shows how $QS could be used for a partial global listing
it only checks the second subscript and writes the value for a match

SAMPLES>k ^rcc
SAMPLES>f i=12:1:19 s ^rcc($j,i)="SUB1=J,"_i
SAMPLES>f i=12:1:15 f j=14,17 s ^rcc($j,j,i)="SUB1="_j_",SUB2="_i
 
SAMPLES>zw ^rcc
^rcc(9372,12)="SUB1=J,12"
^rcc(9372,13)="SUB1=J,13"
^rcc(9372,14)="SUB1=J,14"
^rcc(9372,14,12)="SUB1=14,SUB2=12"
^rcc(9372,14,13)="SUB1=14,SUB2=13"
^rcc(9372,14,14)="SUB1=14,SUB2=14"
^rcc(9372,14,15)="SUB1=14,SUB2=15"
^rcc(9372,15)="SUB1=J,15"
^rcc(9372,16)="SUB1=J,16"
^rcc(9372,17)="SUB1=J,17"
^rcc(9372,17,12)="SUB1=17,SUB2=12"
^rcc(9372,17,13)="SUB1=17,SUB2=13"
^rcc(9372,17,14)="SUB1=17,SUB2=14"
^rcc(9372,17,15)="SUB1=17,SUB2=15"
^rcc(9372,18)="SUB1=J,18"
^rcc(9372,19)="SUB1=J,19"
 
set glob="^rcc",last=14,start=13

SAMPLES>print
a        for  {
         set glob=$q(@glob,1,val) quit:glob=""
         set sub=$qs(glob,3)
         if sub=start write glob," >> ",val,!
         else  if sub]start,sub']last write glob," >> ",val,!
         else  write glob,!
         }

SAMPLES>d a
^rcc(9372,12)
^rcc(9372,13)
^rcc(9372,14)
^rcc(9372,14,12)
^rcc(9372,14,13) >> SUB1=14,SUB2=13
^rcc(9372,14,14) >> SUB1=14,SUB2=14
^rcc(9372,14,15)
^rcc(9372,15)
^rcc(9372,16)
^rcc(9372,17)
^rcc(9372,17,12)
^rcc(9372,17,13) >> SUB1=17,SUB2=13
^rcc(9372,17,14) >> SUB1=17,SUB2=14
^rcc(9372,17,15)
^rcc(9372,18)
^rcc(9372,19)
 

@Guillaume Rongier 
your terminal example is just poor , (sorry!)  pauvre
I do it his way, easy to read and easy to follow, (your notation)

SAMPLES>zzq
SQL Command Line Shell
----------------------------------------------------
The command prefix is currently set to: <<nothing>>.
Enter q to quit, ? for help.
SAMPLES>>  << entering multiline statement mode >>
        1>>CREATE TABLE test.formation (
        2>>    name varchar(50) NULL,
        3>>    room varchar(50) NULL
        4>>)
        5>>go
1.      CREATE TABLE test.formation (
            name varchar(50) NULL,
            room varchar(50) NULL
        )
 
0 Rows Affected
statement prepare time(s)/globals/lines/disk: 0.0122s/1724/14836/0ms
          execute time(s)/globals/lines/disk: 0.4004s/68198/594881/177ms
                          cached query class: %sqlcq.SAMPLES.cls47
---------------------------------------------------------------------------
SAMPLES>>  << entering multiline statement mode >>
        1>>INSERT INTO test.formation
        2>>(name, room)
        3>>VALUES('formation1', 'salle1')
        4>>go
1.      INSERT INTO test.formation
        (name, room)
        VALUES('formation1', 'salle1')
 
1 Row Affected
statement prepare time(s)/globals/lines/disk: 0.0113s/2622/28346/0ms
          execute time(s)/globals/lines/disk: 0.0009s/13/143/0ms
                          cached query class: %sqlcq.SAMPLES.cls48
---------------------------------------------------------------------------
SAMPLES>>q
SAMPLES>

this might do it:

Class User.Scott 
{
ClassMethod Clean(infile, outfile) As %Status
{
  set in=##class(%Stream.FileCharacter).%New()
  do in.LinkToFile(infile)
  set out=##class(%Stream.FileCharacter).%New()
  set out.Filename=outfile
  do in.Rewind()
  while 'in.AtEnd {
    set line=in.ReadLine()
    set last=($e(line,*)="|")
    if last set sc=out.WriteLine(line)
    else  set sc=out.Write(line)
  }
  do in.%Close()
  set sc=out.%Save()
  quit sc
}
}

Just to understand your requirements correctly.
- a linebreak  $c(13,10)  would only be acceptable if it follows a segment terminator "|" 
- IF YES Is this just a pipe | or a double pipe || as in your example?
This could be a processing rule to check the last chars of the line
and ignoré the linebreak at a mismatch.   

 

FOUND SOMETHING !

in SMP IRIS you see this header as in Caché / Ensemble

but click to more  has a surprise in IRIS

Select foreground and you get all %session, .... that you look for.
Recorded with SPOOL , device 2
 
%CSPsc=1
%ROWCOUNT=0
%ROWID=""
%SNGetQueryStats=1
%SYSLOG=1
%application=<OBJECT REFERENCE>[356@%CSP.UI.Portal.Application]
%caller=""
%class="%CSP.UI.Portal.SQL.Home"
%method="InvokeInstanceMethod"
%msg=""
%obj=<OBJECT REFERENCE>[362@%ZEN.Component.html]
%objlasterror=""
%page=<OBJECT REFERENCE>[20@%CSP.UI.Portal.SQL.Home]
%request=<OBJECT REFERENCE>[1@%CSP.Request]
%response=<OBJECT REFERENCE>[2@%CSP.Response]
%sc=1
%session=<OBJECT REFERENCE>[3@%CSP.Session]
%sqlcontext=<OBJECT REFERENCE>[433@%Library.ProcedureContext]
%tStatement=<OBJECT REFERENCE>[369@%SQL.Statement]
%zenContext="method"
%zenThreadId=39
SQLCODE=0
rs=""
<Private variables>
$zp=14828
$io="|TCP|58771"


Reverse engineering of the SMP page uncovered this new checkbox to me.
Could be it is documented somewhere

HTH