Timeline for Command to display first few and last few lines of a file
Current License: CC BY-SA 3.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 28, 2013 at 20:01 | comment | added | Stéphane Chazelas | Note that with seq 3 | ..., line 2 will be output twice which may or may not be desirable, I've taken special care to avoid it in the solution I gave. | |
| Feb 28, 2013 at 19:06 | comment | added | Jander | @Stephane -- Ah, in that case tee quits early, SIGPIPE is sent to seq, and tail prints what from its view is the last line of the stream... in my case, 2679. But I finally understand why tail was getting a SIGPIPE... its output was being fed into head along with tee's. I've updated my answer -- thanks a lot for the debugging help! | |
| Feb 28, 2013 at 19:02 | history | edited | Jander | CC BY-SA 3.0 | Corrected answer for longer input, and added new understanding. |
| Feb 28, 2013 at 17:39 | comment | added | Stéphane Chazelas | @Jander, try feeding more than 8k like seq 100000 | tee >(head -n1) >(tail -n1) > /dev/null | |
| Feb 28, 2013 at 16:44 | comment | added | Jander | @Stephane - I've never seen the SIGPIPE with the >(head) >(tail) syntax. I always do with the | syntax. | |
| Feb 28, 2013 at 16:42 | history | edited | Jander | CC BY-SA 3.0 | Clarified line ordering |
| Feb 28, 2013 at 16:40 | history | post merged (destination) | |||
| Feb 28, 2013 at 16:38 | comment | added | Jander | On my system (bash 4.2.37, coreutils 8.13), tail is the one being killed by SIGPIPE, not tee, and tail isn't writing to a pipe. So it must be from a kill(), right?. And this only happens when I'm using the | syntax. strace says that tee isn't calling kill()... so maybe bash? | |
| Feb 28, 2013 at 16:28 | comment | added | Stéphane Chazelas | You'll get the SIGPIPE with tee >(head) >(tail) for the same reasons (>(...) which by the way is a ksh feature now supported by both zsh and bash as well) uses pipes as well. You could do ... | (trap '' PIPE; tee >(head) >(tail) > /dev/null) but you'll still see some broken pipes error messages from tee. | |
| Feb 28, 2013 at 16:20 | comment | added | Gilles 'SO- stop being evil' | What makes the order likely to be upheld? It probably will be for a large file, because tail has to work longer, but I expect (and do see) it failing about half the time for short inputs. | |
| Feb 28, 2013 at 16:12 | comment | added | derobert | When head or tail finish writing the output they want, they close their stdin and exit. That's where the SIGPIPE is coming from. Normally this is a good thing, they're discarding the rest of the output, so there is no reason for the other side of the pipe to continue spending time generating it. | |
| Feb 28, 2013 at 16:07 | history | answered | Jander | CC BY-SA 3.0 |