打印行6-10:
sed -n '6,10p' file
如果文件很大,并且与行数相比,结束行数量较小,则可以通过以下方式使其更有效:
sed -n '10q;6,10p' file
$wc -l test.txt 368048 test.txt $du -k test.txt 24640 test.txt $time sed -n '10q;6,10p' test.txt >/dev/null real 0m0.005s user 0m0.001s sys 0m0.003s $time sed -n '6,10p' test.txt >/dev/null real 0m0.123s user 0m0.092s sys 0m0.030s