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XksHAH3h44WeDLA7DJQL83oVNwZTiyTov1V6wtuK7sqA9Lczds7A7u3jc5BIGahamwsMmmgtavbQOQW2DD4VdnJJs2tbaw9npMBemGSrjoH0O3D4B6tXkwFgQunq3dZ20fADMqR9uofaasKMkJpP8Zj2ZN7ZlTNn3MAN0IR9KSOWmucgF9VcXlINm9+gQ7g+4jSE6/vFT8F+Vz8qImYOoruWZ1xMXfJK2/5rVzmTwHIk3cMM3iGW2bJfB3FnHfEIgackMeTS/NpGYBNsBKOByuA9KIS5bAxyKAIJcEU2MsqZdwUDdnrh4NtTD0uR2e+WdV+SAm881p7BvItWX2XvORceWy2vq8fJjrnQekaiPCkbCkJrdEbN4I/quYTKrr109YM62bmH1nx0zKd9tX/BDM9vKvCs7xzSw3hEqUrKA7eu2eamtvZ+4QXhaNyGo5aU09BmRR/7uh01vgnO4GADWDfkefC6WALr9cpLHefA2MFxQqTFaXN++sgGGWvRhIl01x14IzJwK9lYALsm9rmasUEnFNGvSNHs4QTksqRmkLBRgsbSXvetDEolX5HZjRClG07FQ1GHUD/cw6UJkTYXksHl7dlQhIeqApWpMQO3IXyme+7kNjT5kVG4hAhpvElopmcA1oENdEzsRnEgl78iFCNNK/9IUkXTkVBk1jN64s1A73ZWvV5ciuFWHDHoC0Fs+K7XR8fu2krd1T2sexM/XfrDm3NOIAu6CGcFEs+zKb/72ZmTj4NhMrtQXwngG2FcdWD+uwnhQjaFKPh7y3hKZJr+um1XGhvAxeEsAWXYgc4MdBj/rk8CcGGw2ERTOueQsEzcwrfrJKlSxDK9rmSt20YDW5xD+Ku2/Uw== CA0B0334 /9zFhSLWksoWG8ZgYQDup4jkWkSeGO/MFz5kyMk3JcXqXHHeAjVyr049/QJWE5prYcIK01x6z83C4M2GC7h/PN2k7ZwtkkpOLG3N3/RdBFHOsluLwIoS2HV1pqHL5pZ+wER/NQ==
Skip to main content (Press Enter).
与以下
#DRECONTENT
Skip
为此,我使用以下命令。
sed -e 's/#DRECONTENT\n.*\nSkip/#DRECONTENT/g' post.idx
但它并不能取代它。有什么想法吗?
答案1
该sed
实用程序读取行。这意味着您无法匹配输入中的换行符,因为这些字符用于分隔行并因此被删除。
但是,您可以这样做:
sed '/^#DRECONTENT$/ { N;N; s/\(\n\).*/\1Skip/; }' file
这会按原样输出输入的所有行,但是当#DRECONTENT
找到准确的行时,会将接下来的两行附加到输入缓冲区以换行符作为分隔符(这是每个人N
所做的)。然后,它将第一个插入的换行符之后的所有内容替换为单词Skip
。
效果是#DRECONTENT
删除之后的第一行,并用单词 替换其后面的行Skip
。所有其他行均未修改。
请注意,标准无法通过在命令的替换部分中sed
使用来插入换行符。我通过捕获我匹配的换行符然后使用反向引用再次插入它来解决这个问题。\n
s