sed 行范围,除了最后一行 [英] sed line range, all but the last line
本文介绍了sed 行范围,除了最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以指定要操作的行范围.比如要对所有行进行操作,(当然是默认的):
You can specify a range of lines to operate on. For example, to operate on all lines, (which is of course the default):
sed -e "1,$ s/a/b/"
但我需要对除最后一行之外的所有内容进行操作.你显然不能使用算术表达式:
But I need to operate on all but the last line. You apparently can't use arithmetic expressions:
sed -e "1,$-1 s/a/b/"
(在这种情况下我使用的是 cygwin,如果它有所不同)
(I am using cygwin in this case, if it makes a difference)
推荐答案
sed -e "$ ! s/a/b/"
这将匹配除最后一行之外的每一行.通过快速测试确认!
This will match every line but the last. Confirmed with a quick test!
这篇关于sed 行范围,除了最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文