Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何将文本粘贴到像awk这样的逐行文本过滤器中,而不使标准文本回显到屏幕上?_Bash_Awk_Named Pipes_Pipe - Fatal编程技术网

Bash 如何将文本粘贴到像awk这样的逐行文本过滤器中,而不使标准文本回显到屏幕上?

Bash 如何将文本粘贴到像awk这样的逐行文本过滤器中,而不使标准文本回显到屏幕上?,bash,awk,named-pipes,pipe,Bash,Awk,Named Pipes,Pipe,我在windows框中的电子邮件中有一条文本,看起来像这样: 100 some random text 101 some more random text 102 lots of random text, all different 103 lots of random text, all the same $ awk '{print $1}' 100 some random text 100 101 some more random text 101 102 lots of random t

我在windows框中的电子邮件中有一条文本,看起来像这样:

100 some random text
101 some more random text
102 lots of random text, all different
103 lots of random text, all the same
$ 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
我想提取数字,即每行的第一个单词。我的Linux机器上有一个运行bash的终端

如果这些文件位于文本文件中,我会这样做:

awk '{print $1}' mytextfile.txt
我想在不创建临时文件的情况下,将这些文件粘贴进来,并将我的数字输出

我天真的第一次尝试是这样的:

100 some random text
101 some more random text
102 lots of random text, all different
103 lots of random text, all the same
$ 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
stdin和stdout的缓冲会对此进行哈希处理。我不介意先打印标准文本,然后再打印标准文本;例如,如果我粘贴到“sort”中,就会发生这种情况,但awk和sed是另一回事

我多想了想: 打开两个端子。创建一个fifo文件。在一个终端上读取fifo,在另一个终端上写入fifo

这确实管用,但我很懒。我不想打开第二个终端。在shell中是否有一种方法可以在我将文本传递到管道时隐藏回显到屏幕上的文本,以便粘贴:

100 some random text
101 some more random text
102 lots of random text, all different
103 lots of random text, all the same
但是看到这个了吗

$ awk '{print $1}'
100
101
102
103
你可以用一个小盒子。我尝试了以下方法,效果很好:

$ awk '{print $1}' << END
> 100 some random text
> 101 some more random text
> 102 lots of random text, all different
> 103 lots of random text, all the same
> END
100
101
102
103
$awk'{print$1}'100一些随机文本
>101更多随机文本
>102个随机文本,全部不同
>103个随机文本,都一样
>结束
100
101
102
103
我将尝试解释我键入的内容:

awk '{print $1}' << END (RETURN)
(PASTE) (RETURN)
END (RETURN)

awk'{print$1}'也许最好的方法是在这里使用shell文档:

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

stty -echo ; awk '{print $1}' ; stty echo

可能会帮助您。

如果您像我一样设置,运行Windows、Xming和PuTTY,您可以执行以下操作:

$ xclip -i[enter]
[right-click-paste]
[ctrl-d]
$ xclip -o | awk '{print $1}'

它要求您设置了X-forwarding,并且您已经安装了
xclip
xsel-i
xsel-o
)这引发了我的一些头脑风暴;我想出了以下方法:smenu()(如果s=,;在$*;do echo“$x”| xsel-I;done中选择x)允许这样的操作:smenu“第一项粘贴,粘贴我”#2,第三项菜单项“1)第一项粘贴2)粘贴我#2 3)第三项菜单项#?在提示下输入“3”将把“第三个菜单项”放入剪切/粘贴缓冲区。非常方便,可以加速windows程序中的重复数据输入。我在commandlinefu.com上添加了这个和你之前的建议。。。希望你不介意。Michael,stty对tty是全局的,还是可以通过流程进行本地化?(stty-echo;awk“打印$1”)