使用linux“剪切”使用标准输入

发布于 2024-08-20 22:04:20 字数 824 浏览 6 评论 0原文

我正在尝试将数据通过管道传输到“剪切”中,例如剪切掉第一列文本。这有效

$ cat test.txt | cut -d\  -f2-

从标准输入读取也有效:

$ cut -d\  -f2- -
? doc/html/analysis.html
? doc/html/classxytree-members.html
<CTRL+D>

但是,一旦涉及管道,它就不再接受我的 ,并且我无法发出“文件结束”信号:

$ cut -d\  -f2- - | xargs echo

更新:这显然是旧版本 bash (3.00.15) 中的一个错误。它确实可以在更新的版本中工作(尝试过 4.0.33 和 3.2.25)。不过,最好有一些解决方法,因为我无法轻松升级。


背景:我有一个脚本/oneliner,它以

? filename

例如以下 形式为我提供了 cvs status (我知道,CVS...)的压缩输出对于尚未提交的文件。我希望能够复制+粘贴该命令的部分输出,并将其用作另一个命令的输入,该命令将这些文件添加到 cvs 中。说:

$ cut -d\  -f2- | xargs cvs add
<paste lines>
<CTRL-D>        # <-- doesn't work

想法?

I'm trying to pipe data into "cut" to, say, cut away the first column of text. This works

$ cat test.txt | cut -d\  -f2-

Reading from stdin also works:

$ cut -d\  -f2- -
? doc/html/analysis.html
? doc/html/classxytree-members.html
<CTRL+D>

However, as soon as a pipe is involved, it doesn't accept my <CTRL+D> anymore, and I can't signal "end of file":

$ cut -d\  -f2- - | xargs echo

Update: This is apparently a bug in an old version of bash (3.00.15). It does work in more recent versions (tried 4.0.33 and 3.2.25). It would be nice to have some workaround, though, since I can't easily upgrade.


Background: I've got a script/oneliner that gives me a condensed output of cvs status (I know, CVS...) in the form

? filename

e.g. for a file not committed yet. I'd like to be able to copy+paste parts of the output from that command and use this as an input to another command, that adds these files to cvs. Say:

$ cut -d\  -f2- | xargs cvs add
<paste lines>
<CTRL-D>        # <-- doesn't work

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春夜浅 2024-08-27 22:04:20

你试过吗

$ cat | cut -d\  -f2- | xargs cvs add
<paste lines>
<CTRL-D>        # <-- doesn't work

have you tried

$ cat | cut -d\  -f2- | xargs cvs add
<paste lines>
<CTRL-D>        # <-- doesn't work
Bonjour°[大白 2024-08-27 22:04:20

你的例子对我来说效果很好。你用什么外壳?什么公用事业?

有时让人困惑的一件事是 Ctrl-D 仅当它是行中的第一个字符时才有效。如果复制并粘贴,有时可能会意外地将空格作为该行的第一个字符,或者在粘贴块的末尾没有换行符,在这种情况下 Ctrl-D 不起作用。只需按回车键,然后再次尝试 Ctrl-D 即可,看看是否可以解决您的问题。

Your examples work fine for me. What shell are you using? What utilities?

One thing that sometimes trips people up is that Ctrl-D only works if it's the first character in the line. If you copy and paste, you might sometimes accidentally have whitespace as the first character of the line, or no newline at the end of the pasted block, in which case Ctrl-D won't work. Just hit return and then try Ctrl-D again and see if that fixes your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文