我有一段文本,其中一些部分由四空格缩进清晰地界定:
PERCHANCE he for whom this bell tolls may be so ill, as that he knows not it
tolls for him; and perchance I may think myself so much better than I am, as
that they who are about me, and see my state, may have caused it to toll for me,
and I know not that.
The church is Catholic, universal, so are all her actions; all that she does
belongs to all. When she baptizes a child, that action concerns me; for that
child is thereby connected to that body which is my head too, and ingrafted into
that body whereof I am a member.
And when she buries a man, that action concerns me: all mankind is of one
author, and is one volume; when one man dies, one chapter is not torn out of the
book, but translated into a better language; and every chapter must be so
translated; God employs several translators; some pieces are translated by age,
some by sickness, some by war, some by justice; but God's hand is in every
translation, and his hand shall bind up all our scattered leaves again for that
library where every book shall lie open to one another.
As therefore the bell that rings to a sermon calls not upon the preacher only,
but upon the congregation to come, so this bell calls us all; but how much more
me, who am brought so near the door by this sickness.
There was a contention as far as a suit (in which both piety and dignity,
religion and estimation, were mingled), which of the religious orders should
ring to prayers first in the morning; and it was determined, that they should
ring first that rose earliest.
我希望每个缩进块前面紧接着START QUOTE
并立即跟进END QUOTE
。我已经使用 sed 玩了十五分钟,但仍然不能完全正确。这是我迄今为止所做的最大努力:
#!/usr/bin/sed -Ef
/^$/ {
N
/\n / {
P
s/^\n//
i\
START QUOTE
}
}
/^ / {
N
/\n$/ {
s/\n$/&END QUOTE/
G
}
}
Running ./parse.sed <script.txt
,我得到以下输出:
PERCHANCE he for whom this bell tolls may be so ill, as that he knows not it
tolls for him; and perchance I may think myself so much better than I am, as
that they who are about me, and see my state, may have caused it to toll for me,
and I know not that.
START QUOTE
The church is Catholic, universal, so are all her actions; all that she does
belongs to all. When she baptizes a child, that action concerns me; for that
child is thereby connected to that body which is my head too, and ingrafted into
that body whereof I am a member.
And when she buries a man, that action concerns me: all mankind is of one
author, and is one volume; when one man dies, one chapter is not torn out of the
book, but translated into a better language; and every chapter must be so
translated; God employs several translators; some pieces are translated by age,
some by sickness, some by war, some by justice; but God's hand is in every
translation, and his hand shall bind up all our scattered leaves again for that
library where every book shall lie open to one another.
START QUOTE
As therefore the bell that rings to a sermon calls not upon the preacher only,
but upon the congregation to come, so this bell calls us all; but how much more
me, who am brought so near the door by this sickness.
END QUOTE
There was a contention as far as a suit (in which both piety and dignity,
religion and estimation, were mingled), which of the religious orders should
ring to prayers first in the morning; and it was determined, that they should
ring first that rose earliest.
注意遗漏的END QUOTE
在第一个引用的块上。我认为这里发生的是脚本中的第二个命令:
/^ / {
N
/\n$/ {
s/\n$/&END QUOTE/
G
}
}
如果当前行是引用块的最后一行,则只能正确找到块末尾的边界。但有时,它会偏离一,并且边界会被分成两个单独的部分N
命令,因此无法识别。有关执行此操作的正确方法的任何指示sed
is?