SED:
原文链接:https://www.f2er.com/bash/388184.htmlsed '1p;/pattern/!d' input.txt
AWK:
awk 'NR==1 || /pattern/' input.txt
grep1:
grep1() { awk -v pattern="${1:?pattern is empty}" 'NR==1 || $0~pattern' "${2:?filename is empty}"; }