tags:

views:

484

answers:

3

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?

+1  A: 

have you tried

$ cat | cut -d\  -f2- | xargs cvs add
<paste lines>
<CTRL-D>        # <-- doesn't work
Lachlan Roche
This works in principle, but not in my case. Turns out the problem was a very old bash version.By the way, the `cat` in your example does nothing and can be omitted. It just pipes the keyboard input to `cut`, which you get anyway when calling cut without filename.There's an old joke that it's considered animal cruelty to send cats through pipes ;-).
jdm
A: 

I cannot recreate this bug. End of file (Ctrl+D) is detected properly for me. I'm using bash v3.1.0 from MSYS on Windows 7.

Jamer
A: 

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.

Brian Campbell
I tried it again on Ubuntu Karmic (9.10), and indeed, it works as expected. It turns out that my work computer is using the archaic bash 3.00.15 (which I'm stuck with, we're using an old Linux distribution to run "legacy" software). It would be nice to find a workaround that works there too, though.
jdm