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

Filter PC/Mac line endings from pasteboard data UNIX
Here's a handy alias for your profile:
alias pbpaste="pbpaste | perl -pe 's/\r\n|\r/\n/g'"
It guarantees that any output from pbpaste will have Unix line endings.

[robg adds: Some people (myself included) don't like to overwrite the built-in commands with their own aliases. If that's the case for you, too, just change the word after alias to whatever you'd like to call the new command. To make this new command permanent, include it in your .bash_profile file in your user's home directory. An earlier hint discusses Unix vs. Mac line breaks, and explains how the above Perl script works.]
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[6,043 views]  

Filter PC/Mac line endings from pasteboard data | 4 comments | Create New Account
Click here to return to the 'Filter PC/Mac line endings from pasteboard data' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Filter PC/Mac line endings from pasteboard data
Authored by: lugal on Apr 04, '05 10:49:31AM

Very nice. I'd been using something similar (w/ tr instead of perl) to convert Mac line endings to Unix, but this is more powerful. WRT Rob's comment about overwriting "pbpaste," you could try using the following:

alias pbconvert="pbpaste | perl -pe 's/\r\n|\r/\n/g' | pbcopy"

This simply replaces the contents of the clipboard w/ the cleaned up text. You can then paste the cleaned up text with Command-V or "pbpaste." I've been doing this, with my old version of the alias, for quite a while, and it's been really useful.



[ Reply to This | # ]
flip it! flip it good.
Authored by: mistersquid on Apr 04, '05 11:34:01PM

Personally, I like the flip tool which macosxhints covered in a previous article even. As Rob says there, no need for aliases.

If you'd like one, you can download the man page I made by converting the instructions Craig Stuart Sapp (author of flip) provides.

[ Reply to This | # ]

Sed?
Authored by: Lectrick on Apr 05, '05 01:48:42AM

Why fire up an entire Perl interpreter when you could do the exact same thing with the "sed" command?

---
In /dev/null, no one can hear you scream



[ Reply to This | # ]
Filter PC/Mac line endings from pasteboard data
Authored by: adrianm on Apr 05, '05 03:26:36AM

Why fire up an entire sed interpreter when you could do the exact same thing with the "perl" command?

Seriously though, perl takes about twice as long to run as sed in this case, but both are around the 100th of a second (on my mac), and both waaaaay longer than it takes to type 'pbpaste' etc.



[ Reply to This | # ]