how do I paste text to a line by line text filter like awk, without having stdin echo to the screen?

Posted by Barton Chittenden on Stack Overflow See other posts from Stack Overflow or by Barton Chittenden
Published on 2010-02-05T22:45:06Z Indexed on 2010/05/08 3:58 UTC
Read the original article Hit count: 315

Filed under:
|
|
|

I have a text in an email on a windows box that looks something like this:

100 some random text
101 some more random text
102 lots of random text, all different
103 lots of random text, all the same

I want to extract the numbers, i.e. the first word on each line. I've got a terminal running bash open on my Linux box...

If these were in a text file, I would do this:

awk '{print $1}' mytextfile.txt

I would like to paste these in, and get my numbers out, without creating a temp file.

my naive first attempt looked like this:

$ awk '{print $1}'
100 some random text
100
101 some more random text
101
102 lots of random text, all different
103 lots of random text, all the same

102
103

The buffering of stdin and stdout make a hash of this. I wouldn't mind if stdin all printed first, followed by all of stdout; this is what would happen if I were to paste into 'sort' for example, but awk and sed are a different story.

a little more thought gave me this: open two terminals. Create a fifo file. Read from the fifo on one terminal, write to it on another.

This does in fact work, but I'm lazy. I don't want to open a second terminal. Is there a way in the shell that I can hide the text echoed to the screen when I'm passing it in to a pipe, so that I paste this:

100 some random text
101 some more random text
102 lots of random text, all different
103 lots of random text, all the same

but see this?

$ awk '{print $1}'
100
101
102
103

© Stack Overflow or respective owner

Related posts about bash

Related posts about awk