Created
September 15, 2021 19:01
-
-
Save Hermann-SW/5a594f053809a3d395f740a5cccada44 to your computer and use it in GitHub Desktop.
Parallel recursive bash mergesort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tms="/tmp/ms.$1" | |
rm -f ${tms}[01] | |
IFS='' | |
while read line1 | |
do | |
let n1=n1+1; echo $line1 >> ${tms}0 | |
if read line2; then let n2=n2+1; echo $line2 >> ${tms}1; fi | |
done | |
tsm="/tmp/sm.$1" | |
if [[ n1 -gt 1 ]]; then (cat ${tms}0 | $0 ${1}0)& else cp ${tms}0 ${tsm}0& fi | |
pid1=$! | |
if [[ n2 -gt 1 ]]; then (cat ${tms}1 | $0 ${1}1)& else cp ${tms}1 ${tsm}1& fi | |
pid2=$! | |
wait $pid1 $pid2 | |
# echo "merge(${tsm}0,${tsm}1)" | |
cmd="comm ${tsm}0 ${tsm}1 | sed \"s/^\t\t\(.*\)$/\10xa\1/; s/^\t//\"" | |
if [[ "$1" != "" ]]; then out=" > /tmp/sm."$1; fi | |
eval $cmd $out | |
rm /tmp/ms.${1}[01] /tmp/sm.${1}[01] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.raspberrypi.org/forums/viewtopic.php?f=31&t=319687