Search code examples
linuxpipeline

Pipeline in linux command is not working.


I just want to create a file filled with half of increasing numbers followed by half of decreasing numbers using pipeline. So I could automate the process to generate thousand of files. Below is my code and generated files output.

shuf -i 1-10 -n 6 | sort -n |shuf -i 11-20 -n 6|sort -r > a.txt

20 18 17 13 12 11


Solution

  • You can separate them into two commands:

    shuf -i 1-10 -n 6 | sort -n > a.txt && shuf -i 11-20 -n 6 | sort -r >> a.txt
    

    >> allows you to append to file

    && to execute a second command in one line