On Mon, Jun 28, 2021 at 06:10:34PM +0200, lisa-asket@perso.be wrote:
> print-lines() {
> if (($# != 3)); then
> echo 'usage: print-lines startnum endnum startdir' >&2
> return 1
> fi
>
> find "$3" \( ... \) \
> -exec awk -v a="$1" -v b="$2" 'FNR >= a && FNR <= b' {} +
> }
This has gotta be some sort of web-based MUA. It destroyed all
the indentation. :(
How do people *use* these things?
> * Your awk command does as I wish. How can I add the file name before each
> output? Â
2. The questioner will keep changing the original question until it
drives the helpers in the channel insane.
Now I'm wondering what "each output" means. Each line? Each file's
block of lines?
Here's an answer to one of those:
unicorn:~$ awk -v a=2 -v b=4 'FNR >= a && FNR <= b {print FILENAME ": " $0}'
foo bar
foo: b
foo: c
foo: d
bar: 2
bar: 3
bar: 4
Of course, this means you will want the *other* one.
21. If^H^HWhen the newbie's question is ambiguous, the proper
interpretation will be whichever one makes the problem the hardest
to solve.