3 # Copyright (C) 2007-2022 Ole Tange, http://ole.tange.dk and Free
4 # Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <https://www.gnu.org/licenses/>
18 # or write to the Free Software Foundation, Inc., 51 Franklin St,
19 # Fifth Floor, Boston, MA 02110-1301 USA
21 # SPDX-FileCopyrightText: 2021-2022 Ole Tange, http://ole.tange.dk and Free Software and Foundation, Inc.
22 # SPDX-License-Identifier: GPL-3.0-or-later
24 # tty1: asciinema rec demo.cast
25 # tty2: asciinema-manuscript
26 # Run commands in tty2 to set clipboard to next command
29 # S <digit>; sleep this many seconds before executing command
30 # T <digit>; sleep this many seconds before pressing enter
36 T() { echo -n '$ '; sleep $@; echo; }
37 # Wait for asciinema to read all input
40 S 0; # Make some files
41 S 1; seq 100 | parallel --bar seq {}0000 '>' file-{}
43 S 0; # gzip files with -1 .. -7 Note how all combinations are made
44 S 1; parallel --bar gzip {1} '<{2}' '>{2}{1}.gz' ::: -{1..7} ::: *
46 S 0; # Count the bytes in some files. Each job gets its own color
47 S 1; parallel --color --tag wc {} ::: file-99*
49 S 0; # Remove .gz-files
52 S 0; # Make a big file
53 S 1; seq 10000000 > bigfile
55 S 0; # Chop bigfile into parts with 100000 lines (slow)
56 S 0; cat bigfile | parallel --pipe -n100000 cat '>lines-{#}'
60 S 0; # Chop bigfile into parts each ~10mb (faster)
61 S 0; cat bigfile | parallel --pipe --block 10m cat '>10mb-{#}'
64 S 0; # Chop bigfile into one part per CPU thread (fastest)
65 S 0; parallel --pipepart -a bigfile --block -1 \
66 cat '>thread-part-{#}'
67 S 3; ls -l thread-part-*
69 S 0; # Chop bigfile into one part per CPU thread - chop at 000\n
70 S 0; parallel --pipepart -a bigfile --block -1 --recend '000\n' \
75 S 0; # Rename all files to UPPERCASE using a {= perl expr =}
76 S 3; parallel mv {} {= tr/a-z/A-Z/ =} ::: *
79 S 0; # Move files into dirs named after the last char in the name
80 S 1; parallel 'mkdir -p {= $_=chop =}; mv {} {= $_=chop =}' ::: *
83 S 0; # Zip dirs into files
84 S 1; parallel --ll --color --tag zip -r '{= s:/$:: =}'.zip {} ::: */
86 S 0; # Remove the dirs
89 S 0; # Unzip zip files into dirs
90 S 1; parallel --ll --tag 'mkdir {.}; cd {.}; unzip ../{}' ::: *.zip
92 S 0; # Remove zip and dirs
95 S 0; # Paint output of the failing commands
96 S 1; parallel --colorfailed echo Arg:{} ';' exit {} ::: 0 0 1 2 0
98 S 0; # Use a bash function with one argument
105 S 1; parallel doit ::: 1 2 3
107 S 0; # Use a bash function with two argument
109 echo Doing it for $1 $2
114 S 1; parallel doubleit ::: 1 2 3 ::: a b
116 S 0; # Make some logfiles
118 S 1; parallel seq {} '>' log.{} ::: {1..10}
121 S 0; # Simple log rotate
122 S 3; seq 9 -1 1 | parallel -j1 mv log.{} log.'{= $_++ =}'
126 S 0; # Monitor progress of multiple jobs in parallel
127 slowseq() { seq "$@" | pv -qL 20; }
129 S 1; parallel --ll --color --tag slowseq {} ::: 150 {1..60}
136 # $sleep = $sleep/2+100.001;
137 # $sleep = $sleep/2+100.001;
138 # $sleep = $sleep/2+100.001;
139 # return $ms/2+100.001;
140 # if($something_printed) { $ms = $ms/2+100.001; }
146 asciinema rec
- |
tee /tmp
/parallel.c |
147 perl
-ne 's/;?[ST] \d;\s?//;s/; [ST] \d//;
148 /###/ and $mark++ and next;
149 ($mark == 0 or $mark == 4) and print;
150 ' > "$pwd"/parallel.cast