Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Filter clipboard contents via the Terminal UNIX

You can strip out unwanted text or otherwise modify your clipboard by using the pbpaste and pbcopy shell commands from the Terminal. (These were previously discussed in this tip, but this is a new technique.)

Here's an example. Let's say I just copied something from the message history in Proteus, which I have set to display timestamps. I want to remove all the timestamps, which all end in "US/Pacific" -- my time zone. To do this, I'll pipe the clipboard contents through grep, and store the output back on the clipboard.

pbpaste | grep -v 'US/Pacific$' | pbcopy

My paste buffer (clipboard) has now been cleansed of all lines ending in the time zone. I can paste it into other applications without the time zones showing up. There are a number of cool applications for this, including the use of the Unix tr command. Want to rot13 your clipboard? Try this:

pbpaste | tr 'a-zA-Z' 'n-za-mN-ZA-M' | pbcopy
A simple sed script such as this one from sed.sourceforge (more here) will let you convert foreign text to HTML entities if you're pasting into your blog. Removing Microsoft "smart quotes" is also pretty easy using tr, sed, or something like the deMoroniser Perl script. And, yes, you can also pipe it through jive or Swedish chef filters.
    •    
  • Currently 3.20 / 5
  You rated: 3 / 5 (5 votes cast)
 
[12,693 views]  

Filter clipboard contents via the Terminal | 3 comments | Create New Account
Click here to return to the 'Filter clipboard contents via the Terminal' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Filter clipboard contents via the Terminal
Authored by: peterneillewis on May 05, '03 10:35:57PM

Forget doing anything between the pbpaste and pbcopy, this can
be used by itself to strip out the formatting!

#!/bin/sh
pbpaste | pbcopy

Then stick that in your Scripts Folder and presto, easy way to
strip fotns and colouring from text.

Excellent hint, thanks!



[ Reply to This | # ]
Filter clipboard contents via the Terminal
Authored by: Kynn on May 06, '03 12:16:47AM

Oh, excellent point. Thanks!

--Kynn

---
--
http://www.maccessibility.com/

[ Reply to This | # ]

Filter clipboard contents via the Terminal
Authored by: luhmann on May 09, '03 11:03:33AM

how to use the sed scripts mentioned above? I tried and I just
got the path to the script as the contents of my clipboard. (yes,
I made the script "executable" and gave it UNIX line endings).



[ Reply to This | # ]