在你遇到第一个空白线之前,产生档案线的最坏指挥是什么? 例如:
output these
lines
but do not output anything after the above blank line
(or the blank line itself)
awk? 还有一点?
在你遇到第一个空白线之前,产生档案线的最坏指挥是什么? 例如:
output these
lines
but do not output anything after the above blank line
(or the blank line itself)
awk? 还有一点?
sed -e /^$/,$d <<EOF
this is text
so is this
but not this
or this
EOF
http://www.un.org/Depts/DGACM/index_spanish.htm
awk -v RS=
1;{exit}
sed -n -e /./p;/./!q
sed -e /./!{d;q}
sed -e /./!Q # thanks to Jefromi
如何直接造成伤亡?
while read line; do [ -z "$line" ] && break; echo "$line"; done
(Or printf %s
instead of echo
, if your shell is buggy and always handles escapes.)
改为:
sed /^$/Q <file>
Edit: s是路上、路上更快。 See ephemient s response for the Worst edition.
为了做到这一点,你可以:
awk {if ($0 == "") exit; else print} <file>
请注意,我故意写这封信是为了避免使用定期表述。 我不知道内部优化是什么样子,但我怀疑直接细化比较会更快。
# awk !NF{exit}1 file
output these
lines
紧急解决办法
awk /^$/{exit} {print} <filename>
这里使用Perl的解决办法:
#! perl
use strict;
use warnings;
while (<DATA>) {
last if length == 1;
print;
}
__DATA__
output these
lines
but don t output anything after the above blank line
(or the blank line itself)
$ perl -pe last if /^$/ file..
$ perl -lpe last unless length file..
另一种解决办法:
perl -00 -ne print;exit file
perl -00 -pe exit if $. == 2 file