Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 its 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 doesnt work?

share|improve this question
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

1 Answer 1

up vote 2 down vote accepted

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

xclip -o | awk '{print $1}'
share|improve this answer
    
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

 
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.