The "loop and a half"

eryk sun eryksun at gmail.com
Sat Oct 7 11:04:18 EDT 2017


On Sat, Oct 7, 2017 at 1:06 PM, bartc <bc at freeuk.com> wrote:
>
> So I have to copy 33,000 lines from a document, get to the terminal (keeping
> that document open because I'm not done with it), start 'sort', and paste
> those 33,000 lines into the console, then type Ctrl-D. Which then promptly
> prints the newly sorted 33,000 lines onto the console. Then you have to
> select those 33,000 lines (not easy as you now have find the midpoint of
> 66,000 lines of output), copy it, and paste it back into the app.

Just redirect sort's output to the clipboard. In X11 a common program
for this is xclip, e.g. `sort | xclip`, which defaults to the
"primary" clipboard but can also use the "secondary" and "clipboard"
clipboards.

In Windows it's clip.exe, e.g. `sort /u /c | clip`, where /u and /c
are undocumented sort switches to use UTF-16 output and a
case-sensitive sort.

That said, I wouldn't use sort.exe to read input from the Windows
console since it uses the legacy codepage. Instead I'd use the new
Linux subsystem in Windows 10, which as of the Creators update
supports piping between Linux and Windows programs and reads Unicode
from the console. Run `bash` and then `sort | clip.exe`. Finish with
Ctrl+D, and Bob's your uncle. Using MSYS bash.exe and sort.exe (e.g.
from Git for Windows) is another option.



More information about the Python-list mailing list