Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
12 years ago
If I've piped the results of a command to
less and then decided that I want to save the contents to a file, is this possible?
I've tried setting a mark
a at the end of the buffer, and then returning to the top and using
|avi to send the whole contents to
vi, but that doesn't work.
17.5k 14 14 gold badges 61 61 silver badges 74 74 bronze badges
May 31, 2011 at 9:46
Jonathan Day Jonathan Day
1,581 3 3 gold badges 12 12 silver badges 16 16 bronze badges
On my system,
man less says
Save the input to a file. This only works if the input is a
pipe, not an ordinary file.
Works for me!
May 31, 2011 at 10:09
81.4k 19 19 gold badges 133 133 silver badges 203 203 bronze badges
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.
|Xcommand Pipe file between current pos & mark X to shell command.
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
Apr 18, 2014 at 17:05
Joe Shaw Joe Shaw
436 4 4 silver badges 8 8 bronze badges
less is opened, you can save the complete output to a file.
vim, less supports commands.
Just type the key
less will ask you the name of the file where you wish to save the content, just type the file name and then type
Nov 12, 2014 at 19:25
> operator. For example:
less foo.bar > output.txt.
May 31, 2011 at 9:49
1,890 3 3 gold badges 18 18 silver badges 28 28 bronze badges
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
May 31, 2011 at 9:51
5,963 29 29 silver badges 32 32 bronze badges
My answer comes a tad too late I believe. But just for reference,
in response to benroth's concern above: For OSX users there's always the option to dump the contents of the pager to a log file by using the option "-l" (read
DASH ELL) at the colon prompt.
The pager will ask for a log file. Key it and press [CR]
Dec 27, 2015 at 23:27
101 1 1 bronze badge
I wanted to do a slightly different thing: write just the currently visible portion of the text to a file. I found that I could do so using the "|" operator, specifying "." as the mark, and
cat >/tmp/mycopy as the shell command.
Feb 27, 2020 at 21:49
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only