With some python:
#! /usr/bin/python3
import sys
textfile = 'input.txt'
patfile = 'patterns.txt'
with open(textfile) as text:
with open(patfile) as pat:
patterns = [line.strip() for line in pat]
for line in text:
line = line.strip()
print(line)
out = line[:]
for p in patterns:
out = out.replace(p, '|'*len(p))
print(''.join(v if v == '|' else ' ' for v in out))
print(''.join(line[k] if v == '|' else ' ' for k, v in enumerate(out)))
Essentially, this does, for each line in the input file:
- Prints the line, and takes a copy.
- For every pattern, replace the occurrences of the pattern in the line with
|
in the copy.
- Then it prints the copy with everything except
|
replaced with spaces.
- Then it prints the original line's character wherever
|
occurs in the copy, or spaces otherwise.
I assume that the patterns are fixed string which don't contain |
.