xsel

Copy and paste text from command line to X clipboard

brewmacoslinux
Try with needOr install directly
Source

About

Command-line program for getting and setting the contents of the X selection

Commands

xsel

Examples

copy text from a command to clipboard$ echo 'hello world' | xsel -b
paste clipboard contents to terminal$ xsel -b
copy file contents to clipboard$ cat filename.txt | xsel -b
pipe clipboard to another command$ xsel -b | grep 'search term'
clear the clipboard$ xsel -b -c