|
SortParagraph |
Pipelines v1.9 |
.* Example by TenFiftyTwo(c). |
.* &arg1. The number of the paragraph to sort..* &arg2. The sort type (a)scending or (d)escending. .* The pipeline reads its input and selects the specified paragraph and sorts.* it, writing the result back to its caller. .* Note. that if any input record contains the hexadecimal characters x'fc'.* through x'ff'; you will need to substitute the character for another character.* not present in the record. pipe (endchar ?)
in .* Input. | literal xfdfe .* Ensure paragraph is marked. | strip .* Trim off whitespace. | a: locate .* Route out blank records. .* Concatenate groups of records that make up a paragraph. | specs xfc 1 1-* n .* Insert start of line flag. | split after str xfc .* Split into individual records. | b: faninany .* Feed blank records back into pipeline. | join until str xfc .* Join records in current paragraph. | c: nlocate xfd .* Go and mark start of paragraph. | d: faninany .* Feed paragraph marker back into pipeline. | split before str xfd .* Separate records back into paragraph format. .* Select the paragraph that we want to sort. | e: fromlab pat /Para #&arg1*/ .* Select records between the start of the.. | f: tolabel pat xfd2a .* ..paragraph and the start of the next. | sort anycase &arg2 .* Sort the paragraph. | nlocate /Para #/ .* Discard the paragraph marker. | specs recno 1 1-* nw .* Insert leading record number. | g: fanin 1 0 2 .* Merge all the streams. | nlocate /Para #/ .* Discard all paragraph markers. | nlocate xfdfe .* Discard start of file marker. | change xfd // .* Discard blank record marker. | out .* Output. ? a: | specs xfd 1 .* Indicate blank records with a marker. | b: ? c: | specs 1-* 1 write .* Mark the start of a paragraph. /Para#/ n recno strip n | d: ? e: | elastic .* Handle records that come before start.. | g: .* ..of a paragraph. ? f: | elastic .* Handle records that come after the end of.. | g: .* ..a paragraph.