Dimrain13
Dimrain13

Reputation: 1

Read lines as variable in parallel (Bash)

I have this script currently and it works fine, however it would be great if it could run 4-5 of these lines in parallel as I have extra resources available.

How could this be accomplished? I have tried removing thee IFS=read warped around it to read it in externally, but that didnt work for me.

    while IFS= read -r line

    do
      echo "$line"

    var1=$line

#warped script location#

done < /home/somanyvarlines.txt

Upvotes: 0

Views: 135

Answers (1)

Philippe
Philippe

Reputation: 26432

This may be what you wanted :

n=5
while readarray -n $n -t five; test ${#five[@]} != 0; do
    printf "%s\n" "${five[@]}"
    # Do your stuff with array of 5 : "${five[@]}"
done < /home/somanyvarlines.txt

Upvotes: 1

Related Questions