Alex headshot

AlBlue’s Blog

Macs, Modularity and More

From Awk to Paste

Howto Mac 2007

Sometimes I need to do a bunch of processing of files -- whether they be HTML files and I'm grepping for links, or for file names that I need to access from a Jar file. Knowing how to use tools such as awk combined with grep really come in handy. But of course, you probably know this already ...

One of the neat things on the Mac is that you don't have to dump the stuff to /tmp/somefile.txt only to open it in an editor subsequently (e.g. open -e /tmp/somefile.txt) if all you want to do is copy the code into the paste buffer. There's a nifty little tool called pbcopy that takes output from stdin, and then puts it onto the clipboard. There's also the corresponding pbpaste that does it in reverse; if you've got a larger volume of text in the clipboard than the Terminal can handle, simply doing pbpaste > /tmp/somefile.txt will get it out into a file for you.

I figure it's worth mentioning here because there's a lot of new people to the Mac who don't know about these cool little things because they've never used a Mac before. Welcome to my world :-)