April 21, 2022
Summary: head
command prints first lines of given
file. On GNU/Linux and NetBSD -q
option suppreses printing
of headers with filenames, when multiple of them are passed as
arguments. OpenBSD, FreeBSD and MacOS don’t have this switch, so how do
you achieve the same result with basesystem tools only?
The old but powerful AWK (the non-GNU version) included in BSD and MacOS can do this. Let’s say we want first two lines of every supplied file:
== 3 { NR=0; nextfile } NR <= 2' file1 file2 awk 'NR