help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Printing arbitrary line range from files


From: Greg Wooledge
Subject: Re: Printing arbitrary line range from files
Date: Mon, 28 Jun 2021 13:48:58 -0400

On Mon, Jun 28, 2021 at 07:25:37PM +0200, lisa-asket@perso.be wrote:
> Would like as below
> 
> ==> foo <==
> 
> b
> c
> d
> 
> ==> bar <==
> 
> 2
> 3
> 4This is similar to results using `head`.

This is why we want the full problem definition up front.  Piecemeal
modifications always lead to multiple complete rewrites.  It's VERY
frustrating.

Here's one way, using GNU or BSD find's -print0 action to feed a
machine-readable list of pathnames into a while-read loop:

find "$3" \( ... \) -print0 |
  while IFS= read -r -d '' file; do
    printf '==> %s <==\n' "$file"
    sed -n "$1,${2}p" "$file"
  done



reply via email to

[Prev in Thread] Current Thread [Next in Thread]