Swiss File Knife
a command line
free external tools,
- download the free Swiss File Knife Base from Sourceforge. - open the Windows CMD command line, Mac OS X Terminal or Linux shell. - OS X : type mv sfk-mac-i686.exe sfk and chmod +x sfk then ./sfk - Linux: type mv sfk-linux.exe sfk and chmod +x sfk then ./sfk OS X and Linux syntax may differ, check the help within the tool.
sfk parameters and variables support sfk script parameters - look like %1 %2 %3 to %9, or with sfk for windows also like $1 $2 $3. - are used with sfk script and call / label. - are passed into the script or label command chain wherein they are never changed. web reference http://stahlworks.com/sfk-helpvar example: --- file filt.bat begin --- sfk script %~f0 -from begin %* GOTO end sfk label begin +filter %1 %2 +end :end --- file filt.bat end --- typing "filt.bat in.txt -+foo" will run sfk filter using the parameters "in.txt" and "-+foo". under windows %~f0 is the absolute batch filename itself including extension .bat or .cmd. sfk global variables - are set like: sfk setvar myvar="the test text" ... sfk echo foo +setvar myvar ... sfk xed in.txt "/foo*bar/[setvar myvar][part2][endvar]/" ... - are used by further commands in the chain like: sfk ... +getvar myvar sfk ... +echo -var "using #(myvar)" sfk ... +xed "_<foo>*</foo>_[part1][getvar myvar][part3]_" note: to read or use variable contents by a pattern #(name) option -var must be given. this is to avoid unwanted side effects with commands that get "#(" in their input files or input text streams. - allowed variable names: must start with a-z, then a-z0-9_ examples: sfk setvar file=in.txt +filter -var "#(file)" -+foo runs sfk filter, giving the input filename by variable. sfk xex in.txt "/foo=*/[setvar fooval][part2][endvar]/" +echo -var "foo is: #(fooval)" extract foo=(any text) from in.txt, place the found text into variable fooval, then print it.  environment variable access can be done like #(env.varname). varname is case insensitive under windows and uses case on linux. example: sfk -var echo "tmp contains: #(env.TMP)" sfk local command variables - are created directly from input text produced by a previous command in the command chain - are suppported only within some commands like sfk run "... $text ...." runs an external program once for every input line. sfk perline "... $text ..." runs sfk internal commands once for every input line. sfk filter -tabform "... $col1 ... $col2 ..." splits text lines by TAB char, allowing reformatting. type sfk run, sfk perline etc. for further infos. see also sfk setvar set an SFK variable sfk getvar get SFK or environment variable sfk variable output formatting formal syntax: #(-03.4varname) with possible control characters: - format left justified, else right 0 fill with zeros, else with blanks .4 take up to 4 chars from variable example: if variable i contains "1" then command output +echo -var ">#(i)<" >1< +echo -var ">#(3i)<" > 1< +echo -var ">#(-3i)<" >1 < +echo -var ">#(03i)<" >001< example: if variable s contains "abcde" then command output +echo -var ">#(.3s)<" >abc< +echo -var ">#(5.3s)<" > abc< sfk variable functions when reading variable text like #(varname) some extra functions can be applied using #(func(varname,...)). available functions are: strpos(v,'text') get index of text within v strpos(v,-case 'text') same, case sensitive strpos(v,-spat '\x20') using slash patterns strrpos(v,'text') search from right side substr(v,o[,l]) substring from offset o length l. use negative o from right side. [l/r]trim(v) strip whitespace at sides isset(v) tells 1 if v is set, else 0 strlen(v) number of characters in v example: if variable s contains "foo bar" then command output +echo -var "#(substr(a,4,3))" bar +echo -var "#(strpos(a,'bar'))" 4
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.