pipe

How do I read data from stdin to gnuplot and plot same data twice

痴心易碎 提交于 2021-01-28 02:58:17
问题 I have a program that generates data with a couple of input arguments and spits it out to stdout, I pipe this data to gnuplot and plot it (in my case I don't have an intermediate file): $ cat sample_data.dat | gnuplot plot_script.gp sample_data.dat: 0 0.5000 1 0.9225 2 0.2638 3 0.7166 4 0.7492 plot_script.gp #!/usr/bin/gnuplot set terminal wxt size 700,524 enhanced font 'Verdana,10' persist set style line 1 lc rgb '#0060ad' pt 7 lt 1 lw 0.5 # circle blue thin line set style line 2 lc rgb '

Do 'cat foo.txt | my_cmd' and 'my_cmd < foo.txt' accomplish the same thing?

≯℡__Kan透↙ 提交于 2021-01-28 01:24:29
问题 This question helped me understand the difference between redirection and piping, but the examples focus on redirecting STDOUT ( echo foo > bar.txt ) and piping STDIN ( ls | grep foo ). It would seem to me that any command that could be written my_command < file.txt could also be written cat file.txt | my_command . In what situations are STDIN redirection necessary? Apart from the fact that using cat spawns an extra process and is less efficient than redirecting STDIN, are there situations in

BASH: Filter list of files by return value of another command

无人久伴 提交于 2021-01-27 20:04:31
问题 I have series of directories with (mostly) video files in them, say test1 1.mpg 2.avi 3.mpeg junk.sh test2 123.avi 432.avi 432.srt test3 asdf.mpg qwerty.mpeg I create a variable ( video_dir ) with the directory names (based on other parameters) and use that with find to generate the basic list. I then filter based on another variable ( video_type ) for file types (because there is sometimes non-video files in the dirs) piping it through egrep . Then I shuffle the list around and save it out

increment bash variable when piping to function

喜你入骨 提交于 2021-01-27 19:28:48
问题 I'm trying to do the following: function func() # in practice: logs the output of a code block to a file { if [ -z "$c" ]; then c=1 else (( ++c )) fi tee -a /dev/null echo "#$c" } { echo -n "test" } | func { echo -n "test" } | func But the increment doesn't work, the variable c stays '1'. I've seen this thread, but it doesn't work for my case - when I try it, a syntax error appears. 回答1: The trick in the linked question works for me: #!/bin/bash function func() # in practice: logs the output

Refused to display 'https://www.youtube.com/watch?v=oKZRsBjQJOs' in a frame because it set 'X-Frame-Options' to 'sameorigin'

好久不见. 提交于 2021-01-21 11:01:49
问题 I need to place a video from youtube in my website but the URL is a variable, I created a pipe to can put, but don't work. This is my code in HTML file <iframe width="670" height="348" [src]=" video | video" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> the code of my pipe is this export class VideoPipe implements PipeTransform { constructor (private domSanitizer:DomSanitizer ){ } transform(url: string): any { return this.domSanitizer

The order in which pipeline components are executed in shell

こ雲淡風輕ζ 提交于 2021-01-20 06:52:08
问题 ls | wc In which order ls and wc executed here? Or, are | and wc just arguments to ls ? 回答1: In the expression ls | wc , your shell will perform roughly the following actions: start two subshells A and B, with A's standard output connected to B's standar input. In subshell A, start the command ls In subshell B, start the command wc wait until all subshells terminated set $? to the exit status of subshell B (i.e. the exit status of wc ) The bash manpage has more details: Pipelines A pipeline

The order in which pipeline components are executed in shell

点点圈 提交于 2021-01-20 06:51:08
问题 ls | wc In which order ls and wc executed here? Or, are | and wc just arguments to ls ? 回答1: In the expression ls | wc , your shell will perform roughly the following actions: start two subshells A and B, with A's standard output connected to B's standar input. In subshell A, start the command ls In subshell B, start the command wc wait until all subshells terminated set $? to the exit status of subshell B (i.e. the exit status of wc ) The bash manpage has more details: Pipelines A pipeline

Using python Popen to read the last line

做~自己de王妃 提交于 2021-01-04 06:41:07
问题 I have a simple python program: test.py: import time for i in range(100000): print i time.sleep(0.5) I want to use another program that executes the above one in order to read the last line output while the above program is counting. import subprocess process = subprocess.Popen("test",stdout=PIPE) sleep(20) # sleeps an arbitrary time print stdout.readlines()[-1] The problem is that process.stdout.readlines() waits until test.py finishes execution. Is there any way to read the last line that

Using python Popen to read the last line

十年热恋 提交于 2021-01-04 06:40:50
问题 I have a simple python program: test.py: import time for i in range(100000): print i time.sleep(0.5) I want to use another program that executes the above one in order to read the last line output while the above program is counting. import subprocess process = subprocess.Popen("test",stdout=PIPE) sleep(20) # sleeps an arbitrary time print stdout.readlines()[-1] The problem is that process.stdout.readlines() waits until test.py finishes execution. Is there any way to read the last line that

pipe sox play command to stdout

倖福魔咒の 提交于 2020-12-31 06:12:45
问题 So I'm currently trying to stream my microphone input from my raspberry pi (rasbian) to some sort of network stream in order to receive it later on my phone. In order to do this I use arecord -D plughw:1,0 -f dat -r 44100 | top pipe the soundstream from my usb-microphone to stdout which works fine as far as I can see but I needed it to be a bit louder so I can understand people standing far away from it . So i piped it to the sox play command like this : arecord -D plughw:1,0 -f dat -r 44100|