You need to install xsel
to access your clipboard. Then you can just use a small script and piping. I use this to prepend four spaces to my current selection in order to get a version I can paste into StackOverflow editors:
xsel | while IFS='' read a; do echo " $a"; done | xsel
Default for xsel
is to manipulate (or query) your PRIMARY selection (what you just marked with the mouse). You can use the clipboard (C-c, C-v stuff) instead by using the option -b
.
To remove all line breaks from your current clipboard, just try this:
xsel -b | tr '\n' '\r' | sed 's/\r*//g' | xsel -b