Swiss File Knife
a command line
free external tools,
- download the free swiss file knife base from sourceforge. - unpack the tool using winzip or unzip. - open the Windows Command Line or a Linux shell.
sfk head [-lines=n] [-f[ollow] [filename] sfk tail [-lines=n] [-f[ollow] [filename] sfk ... +[t]head | +[t]tail [-lines=n] 1. print first or last lines of a file, optionally following changes. to use file content processing, provide a single filename. 2. print first or last text lines procuded by a previous command. to process chain text, thead or ttail are recommended. options -lines=n print first or last n lines (default is 10). -follow or -f waits for file changes, printing them endlessly. if file is recreated or shrunk, rereads the last lines. if file is changed, head will always reread from front. to post-process tail output, e.g. with +filter, always add +loop at the end of the command sequence. -quiet do not tell verbosely about read restarts. -polltime=n with -follow, specifies the delay in milliseconds before the file is checked again for changes. default is 500. -altsize use a different method to determine the file size (stat instead of seek). may help if the default method fails to read the file, or to improve performance. see also sfk view GUI tool to view all text files of a folder, then jump through file heads/ends by ctrl+pageDown or ctrl+end. examples sfk tail -follow logs\access.log immediately lists last lines, then all added lines over time. sfk tail -f c:\temp\log.txt +filter -+error: -+warning: +loop endless filter of error and warning messages from log.txt. type myfile.txt | sfk filter +thead -lines=50 filter first 50 lines from stdin, via sfk filter. example sfk script with conditional execution file logfilter.txt: sfk label checklog +tail -follow logfile.txt +tee toterm +filter -+error: +if "rc>0" call myalert +loop +end sfk label myalert +run -yes "myalert.bat" +end sfk script logfilter.txt will run myalert.bat whenever errors appear in logfile.txt. scripted example if you want to both tail and filter on several phrases, the command may become hard to read and to edit. as an alternative, you may put it into a batch embedded sfk script, e.g. under windows, create a file filtlog.bat: @echo off sfk script filtlog.bat -from begin goto xend sfk label begin +tail -f log.txt +filter -high red error:* -high yellow warning:* -high blue debug:* +loop :xend then type "filtlog". creating command sequences this way allows better readability, and easy editing in any editor. see also sfk filter - all options for selection and post-processing of text sfk partcopy - copy byte block from the beginning of a file sfk script - how to create script files with sfk commands sfk samp - ready-to-use templates for windows and linux scripts
sfk is a free open-source tool, running instantly without installation efforts. no DLL's,
no registry changes - just get sfk.exe from the zip package and use it (binaries for
windows, linux and mac are included).
read more about all sfk functions here.