1

I'd like to cat file.txt and put the output into the clipboard (to use it later). How can I do it, preferably by a command in bash?

Update: I don't want to copy content of file.txt to another file. I just want to put it content into clipboard (something like Ctrl+C would do in a GUI application) to be able to past it in somewhere later.

Kusalananda
  • 14,885
  • 3
  • 41
  • 52
Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59

4 Answers4

1

UPDATE: It seems xclip -selection clipboard gets the job done.

What you are looking for can be achieved on OS X using pbcopy.

cat file | pbcopy

Alternatively,

pbcopy < file

For linux you can find similar solution here and here. I have not tested them but if it works please let me know.

Community
  • 1
  • 1
forevergenin
  • 1,180
  • 12
  • 14
-1

You can read whole file, save it's content into a variable and operate with it:

CONTENT=`cat file`
...
echo "$CONTENT" > /path/to/somewhere
frist
  • 1,918
  • 12
  • 25
  • I think about system storage, something like ctrl-c but done by bash command. I don't want to copy content to another file. – Michal_Szulc Jul 22 '16 at 13:15
-2

In "system storage", are you referring to your hard drive ?

Anyways, the usual bash command to do that would be:

cat file > path/to/storage/file
Matt
  • 165
  • 2
  • 8
-2

You could just use cat file > new_file which works like copy a file with cp. Imho you shouldn't use cat for tasks like this. If you just want to copy specific data in a new file, grep would be your weapon of choice. For example: grep 'keyword' file > file_with_keyword_foo

Nepooomuk
  • 1
  • 3
  • No, I rather think about system storage, something like ctrl-c but done by bash command. I don't want to copy content to another file. – Michal_Szulc Jul 22 '16 at 13:13