How can I save the current contents of less to a file?
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping
--
Chapters
00:00 How Can I Save The Current Contents Of Less To A File?
00:22 Answer 1 Score 0
00:35 Accepted Answer Score 142
00:46 Answer 3 Score 36
01:12 Answer 4 Score 9
01:26 Thank you
--
Full question
https://superuser.com/questions/290908/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #pipe #less
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping
--
Chapters
00:00 How Can I Save The Current Contents Of Less To A File?
00:22 Answer 1 Score 0
00:35 Accepted Answer Score 142
00:46 Answer 3 Score 36
01:12 Answer 4 Score 9
01:26 Thank you
--
Full question
https://superuser.com/questions/290908/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#bash #pipe #less
#avk47
ACCEPTED ANSWER
Score 142
On my system, man less says
s filename
Save the input to a file. This only works if the input is a
pipe, not an ordinary file.
Works for me!
ANSWER 2
Score 36
The accepted answer doesn't work on the Mac -- as @benroth says, pressing s just moves down a line -- but you can use a different method.
In less --help:
|Xcommand Pipe file between current pos & mark X to shell command.
and
A mark is any upper-case or lower-case letter.
Certain marks are predefined:
^ means beginning of the file
$ means end of the file
So if you go to the top of the buffer (<) and then:
|$cat > /tmp/foo.txt
the contents of the buffer will be written out to /tmp/foo.txt.
ANSWER 3
Score 9
When your less is opened, you can save the complete output to a file.
Like vim, less supports commands.
Just type the key s, then less will ask you the name of the file where you wish to save the content, just type the file name and then type Enter.
Cheers
ANSWER 4
Score 0
No if you have started less, but if you know before yu want to send it to less and a file then you can use the tee command
command | tee out_file | less