advertisement

Article:
  Text Tricks and More Text Tricks
Subject:   more tips
Date:   2006-10-13 07:24:09
From:   sootmann
pbcopy and pbpaste deserve a lot more attention. they're near and dear to my heart--when I started out using Linux, one of the things I wanted, but never got, was a way to get STDOUT into the clipboard. OS X delivers.


pbcopy accepts standard input and pbpaste creates standard output. so, you can `ls | pbcopy` to put the output of 'ls' into the clipboard, or you can `pbpaste > file.txt` to create a new text file with whatever's in the clipboard. Note that there are some Mac/Unix cr/lf/newline issues. If what's being pasted came from the GUI, it probably has Mac line breaks, not Unix newlines. I have a script that uses pbcopy and pbpaste and it has these lines:
# step 1: paste clipboard contents into a temp file
pbpaste > ~/temp1.txt
# convert mac returns to unix newlines
# put newly formatted contents into another temp file
tr '\r' '\n' < ~/temp1.txt > ~/temp2.txt


Also, BBEdit and TextWrangler (and probably others) allow rectangular selections. If you've got a lot of lines like
ABCDEFGH
ABCDEFGH
ABCDEFGH
and you want to remove all the DE's, you can press the option key, then click and drag a rectangle around all the DE's, then press 'delete' once and poof! they're gone.