How to copy text from less

Type the command :s from within less to write the buffer to a 'log' file.

Source: The "s" command is equivalent to specifying -o from within less

  1. install xsel first
  2. copy to clipboard using xsel: less filename.txt | xsel -i
  3. paste it: xsel -o

You can repurpose less's 'v' command for this.

Look at the manpage for less, specifically about LESSEDIT. You can use @rwxrwxrwx's suggestion, if you do a little set-up ahead of time (maybe in your .bashrc):

bash$ export LESSEDIT="%E < %f"
bash$ export EDITOR="xsel -ib"

When less runs, press 'v' to open the present file in the $EDITOR; in this case, open it with xsel -ib < {the file's name}.

Using xsel -ib puts the data on the clipboard, so you can ctrl-V to paste the data where you want it.