GNU sed version 4.6以降は --debug コマンドラインオプションが追加されています。実際に使ってみました。
例
複数行置換を行う。 sed スクリプトを例にとってデバッグ実行してみました。
latexファイルをPANDOC変換したが一部変換できなかったletexコマンドがテキスト中に
:raw-latex:
hogehoge ...
の形で残っている。行をまたぐものがあるので複数行対応置換を行う。
sed実行
$ cat chapter1.00.rst | sed --debug -E -f raw-latex.sed
デバッグ出力
SED PROGRAM:
$! {
H
d
}
$ {
H
x
s/:raw-latex:`\\\\index[^`]+`//g
s/:raw-latex:`\\\\person\\{([^}]+)\\}`/\1/g
}
INPUT: 'STDIN' line 1
PATTERN:
COMMAND: $! {
COMMAND: H
HOLD: \n
COMMAND: d
END-OF-CYCLE:
INPUT: 'STDIN' line 2
PATTERN: The\o37777777702\o37777777640Philosophy of\o37777777702\o37777777640Forth
COMMAND: $! {
COMMAND: H
HOLD: \n\nThe\o37777777702\o37777777640Philosophy of\o37777777702\o37777777640Forth
COMMAND: d
END-OF-CYCLE:
......(中略)......
INPUT: 'STDIN' line 23
PATTERN: programming|see{Structured programming}}`
COMMAND: $! {
COMMAND: }
COMMAND: $ {
COMMAND: H
HOLD: \n\nThe\o37777777702\o37777777640Philosophy of\o37777777702\o37777777640Forth\n=======================\n\nForth is a language and an\noperating system. But that\o37777777742\o37777777600\o37777777631s not all: It\o37777777742\o37777777600\o37777777631s also the embodiment of a\nphilosophy. The philosophy is not generally described as something apart\nfrom Forth. It did not precede Forth, nor is it described anywhere apart\nfrom discussions of Forth, nor does it even have a name other than\n\o37777777742\o37777777600\o37777777634Forth.\o37777777742\o37777777600\o37777777635\n\nWhat is this philosophy? How can you apply it to solve your software\nproblems?\n\nBefore we can answer these questions, let\o37777777742\o37777777600\o37777777631s take 100 steps backwards and\nexamine some of the major philosophies advanced by computer scientists\nover the years. After tracing the trajectory of these advances, we\o37777777742\o37777777600\o37777777631ll\ncompare\o37777777742\o37777777600\o37777777624and contrast\o37777777742\o37777777600\o37777777624Forth with these state-of-the-art programming\nprinciples.\n\n:raw-latex:`\\index{P!Programming cycle:!preliminary\ndesign/decomposition|see{Preliminary design}}`:raw-latex:`\\index{S!Software elegance, history of!structured\nprogramming|see{Structured programming}}`
COMMAND: x
PATTERN: \n\nThe\o37777777702\o37777777640Philosophy of\o37777777702\o37777777640Forth\n=======================\n\nForth is a language and an\noperating system. But that\o37777777742\o37777777600\o37777777631s not all: It\o37777777742\o37777777600\o37777777631s also the embodiment of a\nphilosophy. The philosophy is not generally described as something apart\nfrom Forth. It did not precede Forth, nor is it described anywhere apart\nfrom discussions of Forth, nor does it even have a name other than\n\o37777777742\o37777777600\o37777777634Forth.\o37777777742\o37777777600\o37777777635\n\nWhat is this philosophy? How can you apply it to solve your software\nproblems?\n\nBefore we can answer these questions, let\o37777777742\o37777777600\o37777777631s take 100 steps backwards and\nexamine some of the major philosophies advanced by computer scientists\nover the years. After tracing the trajectory of these advances, we\o37777777742\o37777777600\o37777777631ll\ncompare\o37777777742\o37777777600\o37777777624and contrast\o37777777742\o37777777600\o37777777624Forth with these state-of-the-art programming\nprinciples.\n\n:raw-latex:`\\index{P!Programming cycle:!preliminary\ndesign/decomposition|see{Preliminary design}}`:raw-latex:`\\index{S!Software elegance, history of!structured\nprogramming|see{Structured programming}}`
HOLD: programming|see{Structured programming}}`
COMMAND: s/:raw-latex:`\\\\index[^`]+`//g
MATCHED REGEX REGISTERS
regex[0] = 761-859 ':raw-latex:`\index{P!Programming cycle:!preliminary
design/decomposition|see{Preliminary design}}`'
PATTERN: \n\nThe\o37777777702\o37777777640Philosophy of\o37777777702\o37777777640Forth\n=======================\n\nForth is a language and an\noperating system. But that\o37777777742\o37777777600\o37777777631s not all: It\o37777777742\o37777777600\o37777777631s also the embodiment of a\nphilosophy. The philosophy is not generally described as something apart\nfrom Forth. It did not precede Forth, nor is it described anywhere apart\nfrom discussions of Forth, nor does it even have a name other than\n\o37777777742\o37777777600\o37777777634Forth.\o37777777742\o37777777600\o37777777635\n\nWhat is this philosophy? How can you apply it to solve your software\nproblems?\n\nBefore we can answer these questions, let\o37777777742\o37777777600\o37777777631s take 100 steps backwards and\nexamine some of the major philosophies advanced by computer scientists\nover the years. After tracing the trajectory of these advances, we\o37777777742\o37777777600\o37777777631ll\ncompare\o37777777742\o37777777600\o37777777624and contrast\o37777777742\o37777777600\o37777777624Forth with these state-of-the-art programming\nprinciples.\n\n
COMMAND: s/:raw-latex:`\\\\person\\{([^}]+)\\}`/\1/g
PATTERN: \n\nThe\o37777777702\o37777777640Philosophy of\o37777777702\o37777777640Forth\n=======================\n\nForth is a language and an\noperating system. But that\o37777777742\o37777777600\o37777777631s not all: It\o37777777742\o37777777600\o37777777631s also the embodiment of a\nphilosophy. The philosophy is not generally described as something apart\nfrom Forth. It did not precede Forth, nor is it described anywhere apart\nfrom discussions of Forth, nor does it even have a name other than\n\o37777777742\o37777777600\o37777777634Forth.\o37777777742\o37777777600\o37777777635\n\nWhat is this philosophy? How can you apply it to solve your software\nproblems?\n\nBefore we can answer these questions, let\o37777777742\o37777777600\o37777777631s take 100 steps backwards and\nexamine some of the major philosophies advanced by computer scientists\nover the years. After tracing the trajectory of these advances, we\o37777777742\o37777777600\o37777777631ll\ncompare\o37777777742\o37777777600\o37777777624and contrast\o37777777742\o37777777600\o37777777624Forth with these state-of-the-art programming\nprinciples.\n\n
COMMAND: }
END-OF-CYCLE:
The Philosophy of Forth
=======================
Forth is a language and an
operating system. But that’s not all: It’s also the embodiment of a
philosophy. The philosophy is not generally described as something apart
from Forth. It did not precede Forth, nor is it described anywhere apart
from discussions of Forth, nor does it even have a name other than
“Forth.”
What is this philosophy? How can you apply it to solve your software
problems?
Before we can answer these questions, let’s take 100 steps backwards and
examine some of the major philosophies advanced by computer scientists
over the years. After tracing the trajectory of these advances, we’ll
compare—and contrast—Forth with these state-of-the-art programming
principles.
sedスクリプト
raw-latex.sed
# raw-latex.sed with -E
# multi-line replace.
#
# gnu sed ver 4.6 over
v 4.6
# append pattern-space contents to hold-space at
# all line (not last lines and a last line)
$! {
H
# clear pattern-space(then not print per line)
# and skip follow commands then start next cycle.
d
}
$ {
H
# swap pattern-space and hold-space.
x
s/:raw-latex:`\\index[^`]+`//g
s/:raw-latex:`\\person\{([^}]+)\}`/\1/g
}
# because sed program terminate,
# auto print pattern-space content
今回食わせたテキストファイル
chapter1.00.rst
The Philosophy of Forth
=======================
Forth is a language and an
operating system. But that’s not all: It’s also the embodiment of a
philosophy. The philosophy is not generally described as something apart
from Forth. It did not precede Forth, nor is it described anywhere apart
from discussions of Forth, nor does it even have a name other than
“Forth.”
What is this philosophy? How can you apply it to solve your software
problems?
Before we can answer these questions, let’s take 100 steps backwards and
examine some of the major philosophies advanced by computer scientists
over the years. After tracing the trajectory of these advances, we’ll
compare—and contrast—Forth with these state-of-the-art programming
principles.
:raw-latex:`\index{P!Programming cycle:!preliminary
design/decomposition|see{Preliminary design}}`:raw-latex:`\index{S!Software elegance, history of!structured
programming|see{Structured programming}}`