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

Re: How to save filtered less results in a file or on stdout



On 2021-04-07, David Wright <deblis@lionunicorn.co.uk> wrote:
>> >
>> > But I don't know how vim would do on-the-fly filtering like
>> > less can do with & (not being very familiar with vim).
>> 
>>  :g/pattern/.w! >> output.txt 
>> 
>> I pressed 'v' in less, searched a pattern and wrote the filtered output
>> to a file using the method above. Seemed to work except the results of
>> the filtering are not visualized using this method. Of course, you can
>> visualize them prior to writing the results to a file (:g/pattern).
>> Maybe a little fastidious.
>
> OK, you "pressed 'v' in less", but what was your command line?
> Without that, it's difficult to replicate your actions.
>

I opened a text file in less, pressed 'v' to invoke my default editor (vim),
filtered for *pattern* and wrote the filtered output to a file 
(':g/pattern/.w!>> output.txt'), then quit vim and was returned to 
less again.
 
 curty@einstein:~$ cat son.txt 

 J'ai négligé de lire le encore très volumineux--si j'ose dire--fils,
 mais j'ai remarqué depuis le début (un début perdu dans l'obscurité
 croissante du passé) le même phénomène chez moi que vous décrivez.

 Il semble qu'une différence de gamme dynamique entre les deux supports
 (plus large en ce qui concerne le mini par rapport à la TNT et donc
 donnant l'impression d'être moins fort dans le milieu de plage) pourrait
 expliquer l'effet constaté.

 Si toutefois mon hypothèse de départ est vraie !

 curty@einstein:~$ less son.txt 
 v
 :g/décrivez/.w! >> output.txt
 :q
 now I'm back in less looking at son.txt
 q

 curty@einstein:~$ cat output.txt 
 croissante du passé) le même phénomène chez moi que vous décrivez.
 
Maybe I'm off the mark here. I thought this was what the OP wanted
to do (but natively, as it were; however, I found no method of
doing this with less' native commands).


Reply to: