Hot answers tagged

26

It depends on the OS buffers and the timing between the 10th and 11th writes of dmesg. After head writes 10 lines, it terminates and dmesg will receive SIGPIPE signal if it continues writing to the pipe. Depending on your OS buffer, dmesg will often write more than 10 lines before head consumes them. To see that head had consumed more than 10 lines, you ...


17

Take a look at the POSIX specification for the write() function: The write() function shall fail if: … An attempt is made to write to a pipe or FIFO that is not open for reading by any process, or that only has one end open. A SIGPIPE signal shall also be sent to the thread. So the sequence of events is: The head process exits. This causes all ...


9

Your pipe commands, as a non-terminal destination, are buffering your output. It will show up eventually, but only when quite a lot of output builds up or the ping command exits. You can use ping -c 5 google.com to set a specific number of packets to be sent and then ping will exit. Your output comes back and the pipes should work as expected. Edit: ...


5

You want to use the xargs command: $ ls -ctr | tail -1 | xargs cat This will take the STDOUT of the tail -1 command, and instead of using it as STDIN for the cat command will use it as options to the cat command.


4

The idiom >(...) just means (in layman terms): "the name of a file". And it works as a "name of a file" (sort of, all will be clear in an instant): $ echo <(date) /proc/self/fd/11 Or some other number/name on your OS. But echo does print a name, exactly as if you do: $ echo ProcSubs11 ProcSubs11 And if a file with the label ProcSubs11 exists, ...


4

it seems operationally no different from a simple unnamed pipe. The point is that not every software may support reading from stdin or writing to stdout. Furthermore if you want input from several processes then you cannot tell them apart (without looking at the data itself) with just a pipe: { echo foo; echo bar; } | cat # vs. cat <(echo foo) ...


3

For appending, all you need do is get rid of the extra quotes, e.g., change CONVERTPATH="$(pwd $PATH)" "/" "$(basename $PATH)" to CONVERTPATH="$(pwd $PATH)/$(basename $PATH)" But there are a few problems: pwd does not take an argument; you can use dirname in the case presented. the read command will not set PATH; rename it, e.g., to name the echo ...


3

You can use the -a flag to tee to tell it to append, so if you really have files that match ~/file* you can do echo "help!" | tee -a ~/file* or whatever list of files you actually want If you don't already have those files as @steeldriver surmises, you could create, say, 5 files like echo "help!" | tee -a ~/file{1..5} to create file1 through file5


3

head closes stdin after printing 10 lines. Then dmesg detects that the stdout is closed and exits. To be more precise, dmesg will receive the EPIPE error from the write call to stdout. From the dmesg.c source code here: https://github.com/karelzak/util-linux/blob/v2.27.1/sys-utils/dmesg.c#L654-L659 rc = fwrite(p, 1, len, out) != len; if (rc != 0) { if ...


3

Within a pipeline, all commands are run in a subshell. times reports time spent by the shell and its subshells, but not its parent shell. You can try process substitution instead: times > >( head -n1 ) times > >( read user sys ; echo $user )


2

according to man 7 signal SIGPIPE 13 Term Broken pipe: write to pipe with no readers so the answer should be kill -13 1234 (1234 being your PID) (broken pipe are bad luck ? )


2

screen -dmS workspace; screen -S workspace -X stuff $'ps aux > output-x\n' I first create a detached session with the -d switch, I called my session workspace. I then send my command to the same session with -X stuff, I am using $'', but you could also use double quotes, but have to do a control M instead of a \n, which I don't like so I normally use ...


2

POSIXly: tr -s '[:blank:]' '[\n*]' <file | grep '^[[:lower:]]*$'


2

getreport cannot read from the terminal because it is a background process. man 2 read: EIO : I/O error. This will happen for example when the process is in a background process group, tries to read from its controlling terminal, and either it is ignoring or blocking SIGTTIN or its process group is orphaned. I guess what you want is not possible ...


2

Sometimes it is just easier to profile things: I've created a sample input file: aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc field:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc aaaaa:bbbbb:ccccc shell script 'a.sh': #!/bin/bash for i in `seq 1 1000`; do cat test.dat | grep ^field | head -n1 | sed ...


2

The process substitution rawtopng <(tail myfile) fileout creates a pipe (just like tail myfile | rawtopng - fileout), and passes a name for the pipe to the program. On Linux, rawtopng will see a name like /dev/fd/42, and if it queries the file type, it'll be told that it's a pipe. No write to the filesystem is required (this is an anonymous pipe, not a ...


1

if multiline (9 lines) solution is ok, check below hextail.sh script: #!/usr/bin/env bash #par1==buffsize, par2=xxd-columns-width, par3=sleepVal; defaults: 256 16 0 size=${1:-256}; cols=${2:-16}; cnt=0; hbuff=$(eval printf '00%.0s' {1..$size}) while true; do hbuff=${hbuff:2}$(dd bs=1 count=1 2>/dev/null | xxd -p) #shiftLeft, add 1b printf ...


1

I think you're on the right track! <(tail myfile) will create an Anonymous Named Pipe, and is a type of Bash Process Substitution. Normally, this will pass /dev/fd/XX as the "filename", which is a file descriptor interface to the running process. From the examples in the linked documentation: bash$ wc <(cat /usr/share/dict/linux.words) 483523 ...


1

Here you are: sed 's/[^A-Za-z]\+/\n/g;s/$/\n/;s/[^\n]*[A-Z][^\n]*\n//g;s/\n$//' <input_file | sort -u


1

This can be done easily with a couple of common utilities: cut -d : -f 1 input.txt | uniq cut extracts fields from the input file. -d denotes the delimiter character (in this case a :), and -f 1 says to extract the first field. uniq removes repeated adjacent lines from the input


1

Using UnZip 6.00 of 20 April 2009, I was able to do this: $ date | zip jeff.zip - $ unzip -l jeff.zip Archive: jeff.zip Length Date Time Name --------- ---------- ----- ---- 29 01-21-2016 13:02 - --------- ------- 29 1 file $ unzip -p jeff.zip | cat Thu Jan 21 13:02:31 EST 2016 $ ...



Only top voted, non community-wiki answers of a minimum length are eligible