Hot answers tagged

33

tl;dr: at some point, yes will be blocked from writing if the data isn't being read on the other side. It will not be able to continue executing until either that data is read, or it receives a signal, so you typically don't need to worry about yes writing gigabytes and gigabytes of data. The important thing to remember is that a pipe is a FIFO data ...


3

In your case, when you only need to number the lines which match a pattern, you don't need an additional command: it's simpler and much more efficient to simply use the -n option of grep: $ sudo my-command | grep -n 'foo\|bar' 114: bla bla bla foo 514: bla bar bla bla 810: foo bla bla bla 1919: bla bla bar bla It would be a huge waste of ressources to ...


2

Then I'd like to append .o to each word. There is no need for the round trip through the shell. Make is powerful enough to provide helpers for common operations on file names like this. In your case you want the function with the self-explanatory name addsuffix: DEPENDENCIES = $(addsuffix .o, $(DEPENDENT_FILES)) Which gets you a.o b.o c.o for an input list ...


2

You could use vipe (from moreutils) as: sudo find / -iname '*foo*' 2>/dev/null | vipe | "$SHELL" Where vipe lets you edit the piped input and then feed it to your preferred shell. Or: sudo find / -iname '*foo*' 2>/dev/null | vipe | xclip -sel c To save the edited pipe into the CLIPBOARD X11 selection. vipe will launch the editor stored in $...


2

Welcome to Stack Exchange! Lot's of good info here. Thank you for your due diligence first. The issue I see with your command is that it is "Begging the Question." In other words, it assumes you know the answer before you even start. Let's have a closer look: cat file.txt The contents of "file.txt" will go to STDOUT. If the "cat&...


2

The way a pipe works conceptually, is that it connects the output of the left command to the input of the right command. So the line: whoami | cat > out.txt whoami will print to stdout by default but since there is a pipe it will get connected to the input of cat. So what does this mean? whoami | > out.txt Well, you are saying attach the output of ...


2

I don't really see a reason for xargs here: printf 'scale=2; l(%s)/l(10)\n' "283" | bc -l Alternatives for when the number is read from a file: awk '{ printf "l(%s)/l(10)\n", $1 }' file | bc -l -e 'scale=2' (that's assuming a bc that has -e), or without bc at all: awk '{ printf "%.2f\n", log($1)/log(10) }' file


2

Although command A might produce an endless output, command B will only read a finite amount of it. When command B exits (or closes its input file descriptor), the pipe will be broken. After that, any write into the pipe from command A will cause the kernel to send a SIGPIPE signal to command A. The default action of SIGPIPE is to terminate the process.


1

As mentioned by steeldriver the issue was indeed the extra space between < and (.


1

Use option -e / --pipe-mode to read the text from stdin and process it. This also outputs the text to stdout. $ fortune | spd-say -e Don't feed the bats tonight. Please read the info manual (info spd-say) which contains a few examples.


1

I think the only way you can do this is by writing the command1 output to a file and reading that in command2: set -o errexit command1 < file.txt > 1.out command2 < 1.out Alternatively if command1 < file.txt > 1.out then command2 < 1.out fi Of course, at this point the asynchronous processing benefit of a pipeline is gone.


1

sudo my-command | cat -n | grep 'foo\|bar' Or, as steeldriver mentioned in the comments, nl is probably a better answer.


1

try dos2unix or d2u. If this does not work, then you will have to tell us more about what the characters are.


1

The simple thing to do is to save the file stream into a file and then command1 < file || command2 < file or if command1 < file; then echo 'first command was successful' else command2 < file fi or any similar syntax, depending on what you want to output. If you want the same file stream to be consumed by 2 commands the same time, you ...


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