2

I wanted a simple way to process text in my clipboard without having to create a file. I tried using the following line:

awk '{print $1}' <(cat)

but I couldn't send cat the EOF character using ctrl+d like I normally do. I have a feeling it has something to do with a conflict of the file descriptor its creating to hold the data from cat, but I'm not entirely sure.

In the interim I'm using here documents, but it's ugly.

awk '{print $1}' <<KITTENMITTENStextblahKITTENMITTENS

The problem is it needs to be rather portable (across CLI commands). Any idea on a more elegant solution? Know why the cat line doesn't work?

  • 2
    What if you specify absolutely no parameter? awk '{print $1}', Enter, paste with middle button, Ctrl-D. – manatwork May 1 '12 at 15:56
  • I had originally wanted to do that, but i need to be able to use it with programs that only accept files as arguments :( – user488244 May 1 '12 at 16:02
  • 1
    How are awk and cat related to your clipboard? What value does <(cat) add? Why not just awk '{print $1}' ENTER? – Mikel May 1 '12 at 16:12
  • 1
    Use - if the command supports that syntax, or /dev/fd/0 or /dev/stdin if your systems has that. – jw013 May 1 '12 at 16:36
2

Is xclip available on your machine? With -o parameter it outputs the current X selection to the standard output:

xclip -o | awk '{print $1}'
  • Thats a good idea, but i cant rely on xclip. I do a lot of work over ssh, and sometimes on Macs – user488244 May 1 '12 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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