artnikbrothers
artnikbrothers

Reputation: 297

Bash: save clipboard to a file with line breaks like it was copied

I'm on OS X server try to copy a formatted text from vim and then would like to save it to another file via bash. I want my new file looks like the text that was copied into vim to clipboard - with line breaks, space indentations... instead I get a plain text in one line.

I do this, after copping: echo `pbpaste` > file.txt

Is there a way to save formatted text to the new file?

Upvotes: 1

Views: 323

Answers (2)

Karoly Horvath
Karoly Horvath

Reputation: 96266

No need to echo.

pbpaste > file.txt

The problem was caused by the lack of quotation:

echo `echo "x  x"`    #x x
echo "`echo "x  x"`"  #x  x

Upvotes: 3

Jeff Puckett
Jeff Puckett

Reputation: 40971

wrap it in double quotes

echo "`pbpaste`" > file.txt

Upvotes: 2

Related Questions