GnuWin32 / Cygutils package has two tools for interacting with the Windows clipboard: getclip and putclip. The first copies text from the clipboard to standard output and the second copies text from standard input to the clipboard. These tools are useful when you want to process text from one Windows application before pasting the text into another application, in the following recipe: getclip | <filters> | putclip
.
For example, I want to paste all DLL file names in a folder into a document:
- Navigate to the required folder using 2xExplorer browser.
- Type Alt+a to select all files.
- Type Alt+c to copy all file names. 2xExplorer copies the absolute path for each file.
- Start cmd.exe console.
- In cmd.exe console, enter:
getclip | cut -d\ -fn | grep dll$ | putclip
. cut is GnuWin32 tool which selects a column of data given a column delimiter (-d\
defines backslash) and field number (-fn
defines column n). grep filters the output to only list files with "dll" in their name. - Start editor.
- Paste the text in the clipboard in destination document.
Of course, you can do the same using Excel:
- Navigate to the required folder using 2xExplorer browser.
- Type Alt+a to select all files.
- Type Alt+c to copy all file names. 2xExplorer copies the absolute path for each file.
- Start Excel.
- Paste data in a worksheet column.
- Select all cells by typing Shift+Space.
- Open Convert Text to Columns Wizard by typing Alt+d+e.
- Select Delimited data type by typing Alt+d.
- Type Alt+n to go to page 2.
- Select Other delimiter by typing Alt+o, then enter "\" for paths.
- Type Alt+f run the wizard.
- Start Auto Filter by typing Alt+d+f+f.
- Move to filter column using the mouse (no keyboard shortcuts?) then select from the drop down list (Custom …).
- Select ends width criteria, enter .dll, then press Enter.
- Move cursor to required column and select it using Control+Space.
- Copy column by typing Control+C.
- Start editor.
- Paste the text in the clipboard in destination document.
The Excel solution has many more steps than the getclip-putclip solution but Excel leads you through to a solution step-by-step. If you're familiar with GNU tools, then getclip-putclip recipe is faster to use and much more extensible.
2008-05-07. I should have remembered that the basename command would output the name of the file without the leading path string. See later article More Uses of Getclip-PutClip about how to use basename in a pipeline.
No comments:
Post a Comment