Can `head` read/consume more input lines than it outputs?
$ { head -n 1; cat; } < <(printf 'a\nb\nc\n')
a
What is causing the different output from those scripts?
---
Additional info - this is apparently not just a head
problem:
$ printf 'a\nb\nc\n' | { sed '1q'; cat; }
a
$ printf 'a\nb\nc\n' | { awk '1;{exit}'; cat; }
a
$ { sed '1q'; cat; } < <(printf 'a\nb\nc\n')
a
$ { awk '1;{exit}'; cat; } < <(printf 'a\nb\nc\n')
a
---
What would be a robust, POSIX way in shell (i.e. without just invoking awk or similar once to do everything) to read some number of lines from input and leave the rest for a different command regardless of whether the input is coming from a pipe or a file?
---
This question was inspired by comments under an answer to [_sort the whole .csv based on the value in a certain column_](/a/750386/133219).
Last activity: Jul 4, 2023, 03:05 PM