get text from the windows clipboard, or put text into clipboard from within batch files using sfk fromclip and toclip on the command line.
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-64.exe sfk and chmod +x sfk then ./sfk
Linux: type mv sfk-linux-64.exe sfk and chmod +x sfk then ./sfk.
OS X and Linux syntax may differ, check the help within the tool.
sfk toclip
copy stdin to clipboard as plain text.
type test.txt | sfk toclip
copies the content of ASCII file test.txt into clipboard.
sfk list | sfk toclip
copies a file listing of the current dir into clipboard.
sfk fromclip [-wait] [-clear]
dump plain text content from clipboard to terminal.
-wait : block until plain text is available.
-clear: empty the clipboard after reading it.
Example: turn backslashes into forward slashes.
Imagine you have the following text open within notepad:
foo/bar/systems/alpha1.cpp
foo/bar/systems/alpha2.cpp
foo/bar/systems/beta1.cpp
and for some reason you need the first line in a format like this:
foo\bar\systems\alpha1.cpp
then you may do it this way:
1. mark the first line using SHIFT + CURSOR keys.
2. press CTRL+C or CTRL+INSERT to copy it into clipboard
3. on the windows command line, run this command (e.g. from a batch):
sfk fromclip +filter -rep x/x\x +toclip
4. back in the editor, press CTRL+V or SHIFT+INSERT,
pasting the result from the clipboard.
As you see, the line changed into "foo\bar\systems\alpha1.cpp".
Example: reformat a spreadsheet line for further processing.
Imagine you have the following Excel file open:
and you need the data from line 3 as comma separated values.
Now, if you click left into line 3:
and press CTRL+C, the line is copied into clipboard, however as TAB-
separated data. (at least that's the behaviour seen with Excel.
Other packages like OpenOffice may behave different.)
So if you say on the command line:
sfk fromclip
what you get is
Foo Finance 4498542 1999 950 Dino
how do you turn this into comma-separated values?
we have 5 columns, therefore extend the above command like this
[type the following all in ONE line]:
sfk fromclip +filter -spat -sep "\t"
-form "$col1;$col2;$col3;$col4;$col5"
which will result in this output:
Foo Finance;4498542;1999;950;Dino
to make the data even safer for post-processing, we may surround
every value by quotes this way [type the following all in ONE line]:
sfk fromclip +filter -spat -sep "\t"
-form "\"$col1\";\"$col2\";\"$col3\";\"$col4\";\"$col5\""
this is hard to type, of course, but if you place it into a .bat
file, you only have to type it once. this results in:
"Foo Finance";"4498542";"1999";"950";"Dino"
As ever, the same result may be achieved in may ways.
For example, you may also save the whole spreadsheet data
as a comma-separated file, and then filter it by
sfk filter export.csv "-+Foo Finance"
which should produce the same line.
sfk toclip
copy stdin to clipboard as plain text.
type test.txt | sfk toclip
copies the content of ASCII file test.txt
into clipboard.
sfk list | sfk toclip
copies a file listing of the current dir
into clipboard.
sfk fromclip [-wait] [-clear]
dump plain text content from clipboard to
terminal.
-wait : block until plain text is available.
-clear: empty the clipboard after
reading it.
Example: turn backslashes into forward
slashes.
Imagine you have the following text open
within notepad:
foo/bar/systems/alpha1.cpp
foo/bar/systems/alpha2.cpp
foo/bar/systems/beta1.cpp
and for some reason you need the first line
in a format like this:
foo\bar\systems\alpha1.cpp
then you may do it this way:
1. mark the first line using SHIFT + CURSOR
keys. 2. press CTRL+C or CTRL+INSERT to
copy it into clipboard 3. on the windows
command line, run this command (e.g. from a
batch):
sfk fromclip +filter -rep x/x\x +toclip
4. back in the editor, press CTRL+V or
SHIFT+INSERT, pasting the result from the
clipboard.
As you see, the line changed into "foo\bar\
systems\alpha1.cpp".
Example: reformat a spreadsheet line for
further processing.
Imagine you have the following Excel
file open:
and you need the data from line 3 as comma
separated values. Now, if you click left
into line 3:
and press CTRL+C, the line is copied into
clipboard, however as TAB- separated data.
(at least that's the behaviour seen with
Excel. Other packages like OpenOffice may
behave different.) So if you say on the
command line:
sfk fromclip
what you get is
Foo Finance 4498542 1999 950 Dino
how do you turn this into comma-separated
values? we have 5 columns, therefore
extend the above command like this [type
the following all in ONE
line]:
sfk fromclip +filter -spat -sep "\t"
-form "$col1;$col2;$col3;$col4;$col5"
which will result in this output:
Foo Finance;4498542;1999;950;Dino
to make the data even safer for
post-processing, we may surround every
value by quotes this way [type the
following all in ONE l
ine]:
sfk fromclip +filter -spat -sep "\t"
-form "\"$col1\";\"$col2\";\"$col3\";\
"$col4\";\"$col5\""
this is hard to type, of course, but if you
place it into a .bat file, you only have
to type it once. this results
in:
"Foo Finance";"4498542";"1999";"950";"Dino"
As ever, the same result may be achieved in
may ways. For example, you may also save
the whole spreadsheet data as a
comma-separated file, and then filter it
by
sfk filter export.csv "-+Foo Finance"
which should produce the same line.
you are viewing this page in mobile portrait mode with a limited layout. turn your device right, use a desktop browser or buy the sfk e-book for improved reading.
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).
the Daily Landscape image the Daily Mobile Background