How can I execute a shell script with parallel command or other way to speed up processing
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
while read line; do
read a b c <<< $line
echo "Checking for patterns...$a, $b, and $c"
awk -v b1="$a" -v b2="$b" -v b3="$c" '$0~b1 && $0~b2 && $0~b3' win
match=$(awk -v b1="$a" -v b2="$b" -v b3="$c" '$0~b1 && $0~b2 && $0~b3' win | wc -l)
echo "Found $match games(s) with patterns $a, $b, and $c"
done < mypatterns
could be
Code:
while read a b c
echo "checking patterns now...
I do not know awk that well to know what that line is doing exactly.
but you're repeating the reading in of data. you can split it on the first read.
done < mypatterns
example mypatterns
Code:
$ cat >> mypatterns
dobe bob sally
silly joey bakeoff
$ while read a b c ; do echo "$a"; echo "$b"; echo "$c"; done < mypatterns
dobe
bob
sally
silly
joey
bakeoff
removing one read of the same data will cut some time off.
just 3 random numbers?
or say like 30 random numbers 3 per line
all you are doing is seeing if 3 random numbers match in any order as fast a possible
So you should probably do it the other way round
i.e read the wins and check if they are in the big list
but you put that fist one in the background and go on to the next
and so on
after they have all finished you can then total the results
you may want to keep count of the ones you are putting in background and limit them idk so only four are running at anyone time
create a bunch of randoms in sets of three per line
Code:
for i in {1..100} ; do shuf -i 1-1000 -n 3 | tr '\n' " " >> randoms ; c=$((c>=3?0:c++)) ; echo >> randoms ; done
##just make a bigger list to compar againt
for i in {1..200} ; do shuf -i 1-10000 -n 3 | tr '\n' " " >> ckrandoms ; c=$((c>=3?0:c++)) ; echo >> ckrandoms ; done
you can run them line of commands in the terminal then check the output files to see what the samples looks like.
Code:
#!/usr/bin/env bash
#set -xv
Acount=0
Bcount=0
Ccount=0
while read a b c
do
while read A
do
[[ "$A" =~ "$a" ]] && ((Acount++))
done < ckrandoms #win
while read B
do
[[ $B =~ $b ]] && ((Bcount++))
done < ckrandoms #win
while read C
do
[[ $C =~ $c ]] && ((Ccount++))
done < ckrandoms #win
done < randoms
echo "
A=$Acount
B=$Bcount
C=$Ccount"
something like that perhaps using sub-string checking.
control loop gets the 3 in separate vars. a b c
then using the other file it reads in and checks it by looking at the line of win (file) to check to see if it is within that entire line, if yes, then add count of 1.
36 =~ 32 24 36 = yes add to count
315,000 lines to generate ... its still generating them... it takes time..
Code:
[userx@FreeBSD64ssd test]$ for i in {1..315000} ; do shuf -i 1-1000 -n 3 | tr '\n' " " >> randoms ; c=$((c>=3?0:c++)) ; echo >> randoms ; done
Looks complicated. Will this speed up the processing?
I'll give it a try.
not sure,it is still reading that one file 3 times, as I am generating larger files, and thinking up a different algorithm while waiting.
the three inner loops are just reading in the "win" file as I do not even know what the win files data looks like, each inner loop is using one of the numbers from the main file to check each line of "win" to see if that number is within the line before checking the next line in the "win" file.
I do suppose one can consolidate the conditional and read in "win" only once.
Code:
#!/usr/bin/env bash
#set -xv
Acount=0
Bcount=0
Ccount=0
while read a b c
do
while read win
do
[[ "$win" =~ "$a" ]] && ((Acount++))
[[ "$win" =~ "$b" ]] && ((Bcount++))
[[ "$win" =~ "$c" ]] && ((Ccount++))
done < ckrandoms
done < randoms
echo "
A=$Acount
B=$Bcount
C=$Ccount"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.