Friday, May 25, 2007

Less is more

Very often when working on a project I deal with extremely large application log files which
poor old notepad.exe, or even trusty Ultraedit
just can't deal with.

Enter the windows port of the unix tool less,
which easily opens even the largest logfiles. The problem is
that running it in a command window makes copying text difficult, selecting a page at
a time and pasting it all back together into a file.

Which brings me to my useful tip. To copy any length of text from less to a file try the following.

navigate to the beginning (or end) of the piece of text you wish to copy, type
m
(for mark) and enter a marker letter of your choice at the prompt

navigate to the other end of the piece of text you wish to copy and press
|
(thats the pipe character, is the shifted value of the key '\' )
enter your marker letter at the prompt.
At the exclamation prompt enter

less -oC:\file.txt

where c:\file.txt is the name of the file you wish to write the data to.

This will open a new less session on your new file , you can hit Q to escape this
if you so wish.

Voila, text copied from less under windows.

p.s another quick tip , to make less behave like tail, simply press F while viewing the file.

No comments: