Re: How to save filtered less results in a file or on stdout
On Mon 29 Mar 2021 at 00:45:28 (+0200), l0f4r0@tuta.io wrote:
> 28 mars 2021, 21:27 de deblis@lionunicorn.co.uk:
>
> > When you've used
> > & pattern
> > to display lines containing your pattern, then
> > | . grep pattern > filename
> > will apply the same filter to the lines selected by | ., where
> > I've used . but you could use ^ or $ or a mark instead, as
> > appropriate.
> >
> Indeed, I had noticed that (and even placed myself at the very beginning of the input and used "| $" instead in order to select everything).
>
> However, I was wondering if there was an alternative when one doesn't need to reenter the same pattern twice for such a basic need...
>
> No easy condensed way for that? :)
It's not a workflow that I'm in the habit of using, but anyway, having
come up with a pattern that's producing the lines you're interested in,
I would:
. type & again,
. UpArrow to recall this latest pattern that you're happy with,
. LeftDrag the mouse to copy the pattern,
. Backspace to rubout the line (the & remains there),
. type | and respond appropriately to the mark: prompt,
. type your shell command:
. grep '
. paste the pattern with whichever button you use
. ' > filename
Using the ' quote will cater for most patterns, though you
might have to adjust for any backslashes in the pattern,
and so on, using Left/RightArrow, or even use " if the
pattern itself contains ' characters.
I tend to paste with Shift-Insert (needs less hand-eye coordination).
Cheers,
David.
Reply to: