Less with multiple files; command to output filenames

less

I want to be able to manually go through many files using less *.txt and then proceeding through the files using :n. If I determine that a file needs to be processed, then I want to be able to give a command that will, for example, send the current file name to stderr, so that once I am done going through all the files, I have a list of filenames to be processed. Is something like this possible? Is there another tool that is better for this purpose?

Best Answer

You can setup your own less special command key. Create file ~/.lesskey and place in it, at the start, the 2 lines:

#command
ok shell echo % >>/tmp/list\n

Then give the command

lesskey

to compile the file. Run your less command on your files and when you want to save the filename type the 2 chars ok. You will see echoed:

!echo myfilename >>/tmp/list
!done  (press RETURN)

which saves the current filename (%) into /tmp/list. Press return to continue. I chose the command ok arbitrarily. You can use any single character or character sequence you like. You can append the :n command to the end of the shell line in ~/.lesskey to also move on to the next file.


If you don't have lesskey I ran it on the above file and passed it through base64 as it contains some binary. Perhaps you can try using this:

echo 'AE0rR2MaAG9rAJtlY2hvICUgPj4vdG1wL2xpc3QKOm4AZQAAdgAAeEVuZA==' | base64 -d >~/.less
Related Question