回答:
1つの方法を次に示します。
ed -s infile <<IN
v/PATTERN/d # delete all lines NOT matching PATTERN
,w !head -n20 # pass the addressed lines as input to shell command
u # undo deletion: not needed if you don't save changes
q # quit editor
IN
ed
、| head -n20
?