Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a files where I need to copy their contents to another file or into an application and rather than open it up, select all the text then copy and paste I'd like to know if I can effectively cat the file contents into the clipboard. Is this possible?

A Windows program would be fine but something that works on Linux would be useful too. I don't use a Mac but it might be useful to others. Bonus points if this can be done on the command line.

share|improve this question
1  
Aha, I knew it was asked before, for Windows: "How to pipe text from command line to the clipboard" at superuser.com/questions/97762/… Maybe leave this open for Linux then? –  Arjan Feb 25 '10 at 21:56
1  
Suburb. Looks like I can use clip.exe for this. Would still like a non-command line version though. Maybe via Windows Explorer context menu? –  Jonathon Watney Feb 25 '10 at 22:08
add comment

5 Answers

Since you didn't ask about Macs: cat file | pbcopy (and likewise pbpaste) for those.

share|improve this answer
    
Darn. I don't use a Mac. Will keep for future reference though. ;) –  Jonathon Watney Feb 25 '10 at 21:53
add comment

xclip (probably available in your Linux system's repos) will work for any X11 system, including most Linux versions, or even X being run under windows or Mac OSX.

share|improve this answer
1  
Example usage: xclip -sel clip < ~/.ssh/id_rsa.pub –  wim Mar 12 '13 at 4:48
add comment

In Linux, you can use xsel to mimic pbcopy and pbpaste:

alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'

Source: Where's Walden? » pbcopy and pbpaste for Linux

share|improve this answer
add comment

On Linux and possible other systems which support xclip:

xclip -i -selection c file_to_copy_to_clipboard.txt

I saw @JustinSmith also mentioned xclip but was missing an example, so had to look it up myself.

Another useful one: paste your clipboard to a file.

xclip -o -selection c > file_to_paste_to.txt

Source

share|improve this answer
add comment

Use this program f2clip. Run it from the command line. It copies file contents into clipboard. I use it for copying text files into web browser for further processing. Download it from http://smrz.xf.cz/f2clip.exe or write your own from this source (it's ugly):

 program f2clip;

 {$APPTYPE CONSOLE}

 uses
SysUtils,
clipbrd;

var i,r:integer;
    s:string;
 f:file;
 buf:array[0..1024*1024-1] of byte;

 data:string;
 d:pointer;
 begin
 try

 { TODO -oUser -cConsole Main : Insert code here }
    if (paramcount=0) then begin
    writeln('parameters: f2clip filename.txt');
end else begin
    write('parameter count: ');
  writeln(paramcount);  
    for i:=1 to paramcount do begin
    s:=paramstr(i);
    writeln('file: ',s);

    assignfile(f,s);
    reset(f,1);
    BlockRead(f,buf,1024*1024,r);
    writeln('size: ',r);
    buf[r]:=0;

    d:=@(buf[0]);
    data:=PAnsiChar(d);
Clipboard.AsText := data;
    close(f);
  end;

  end;

 except
   on E:Exception do
     Writeln(E.Classname, ': ', E.Message);
 end;
end.

Sorry.

share|improve this answer
    
+1. I appreciate this effort though I think xclip is a better solution. –  0xc0de Sep 29 '13 at 18:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.