Quantcast
Channel: User ozzy - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 31

Answer by ozzy for Run parallel command and redirect the output to files with specific name

$
0
0

Well, this is a somewhat over-engineered Bash-solution, but it works and hopefully clarifies the use of the parallel command:

function xx(){ curl "https://jsonplaceholder.typicode.com/todos/$1" > "$1.txt";}
parallel xx -- {1..100}

The first line creates a new "command" or function called xx which - when executed - causes the execution of a curl command that has its stdout redirected to a file. The xx function takes a single number as its argument; inside the body of the function, it is referred to as `$1', i.e. the first positional parameter.

The second line demonstrates the use of the parallel command, which runs xx once for (and with) each argument from the list 1, 2, 3, ..., 100 (the list 1 2 3 ... 100 is generated by the shell when it performs brace expansion on {1..100}).

NOTE: this answer relates to the parallel command in the moreutils package on Debian systems, not to the GNU parallel command.


Viewing all articles
Browse latest Browse all 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>