How to resolve the algorithm Search in paragraph's text step by step in the J programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Search in paragraph's text step by step in the J programming language
Table of Contents
Problem Statement
The goal is to verify the presence of a word or regular expression within several paragraphs of text (structured or not) and to format the output of the relevant paragraphs before putting them on the standard output. So here, let’s imagine that we are trying to verify the presence of a keyword "SystemError" within what I want to call "the paragraphs" "Traceback (most recent call last):" in the file Traceback.txt The expected result must be formated with ---------------- for paragraph's separator AND "Traceback (most recent call last):" as the beginning of each relevant's paragraph :
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Search in paragraph's text step by step in the J programming language
Source code in the j programming language
NB. read file, separate on blank lines
paragraphs=: ((LF,LF)&E. <;.2 ])fread 'traceback.txt'
NB. ignore text preceding 'Traceback (most recent call last)'
cleaned=: {{y}.~{.I.'Traceback (most recent call last)'&E.y}}each paragraphs
NB. limit to paragraphs containing 'SystemError'
searched=: (#~ (1 e.'SystemError'&E.)every) cleaned
NB. add "paragraph 'separator'" and display
echo ;searched ,L:0 '----------------',LF
You may also check:How to resolve the algorithm Factorial step by step in the Factor programming language
You may also check:How to resolve the algorithm Parameterized SQL statement step by step in the C# programming language
You may also check:How to resolve the algorithm Filter step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the REXX programming language
You may also check:How to resolve the algorithm Stirling numbers of the second kind step by step in the Sidef programming language