Julia defines a pipeline function to redirect the output of a command as the input to the following command:
This writes the contents of the file referred to by $file into test.txt, which is shown as follows:
This pipeline function can even take several successive commands, as follows:
run(pipeline(`echo $("\nhi\nJulia")`,`cat`,`grep -n J`)) #> 3:Julia
If the file tosort.txt contains B, A, and C on consecutive lines, then the following command will sort the lines:
run(pipeline(`cat "tosort.txt"`,`sort`)) # returns A B C
Another example is to search for the word is in all the text files in the current folder. Use the following command:
run(`grep is $(readdir())`) ...