0

I haven't explained this question enough so it was misunderstood as duplicate.

I want to read N lines each time of a CSV file and execute a script that operates the lines (names). How can I send N lines as an argument to another script and execute it in parallel?

The file is a CSV with +400000 lines like this:

nombre,ape_paterno,ape_materno
ALFREDO,AGUILAR,AGUILAR
ANGEL,AGUILAR,AGUILAR
CARLOS,AGUILAR,AGUILAR
DANIEL,AGUILAR,AGUILAR
EDUARDO,AGUILAR,AGUILAR
ELIZABETH,AGUILAR,AGUILAR
FERNANDO ,AGUILAR,AGUILAR
FRANCISCA,AGUILAR,AGUILAR
FRANCISCO ,AGUILAR,AGUILAR
FRANCISCO JAVIER,AGUILAR,AGUILAR
...

I want something like this:

{
read 
while IFS="," read $N lines
do 
   sh ${DIR}/Downloader.sh $N-Lines-as-argument &
done } < "$input"
wait

I have tried the answers from here but my result gives null.

8
  • It is a duplicate, did you try answers from any of those other page? Commented Apr 6, 2017 at 18:36
  • What is your bash version? Commented Apr 6, 2017 at 18:43
  • @Inian Yes, my output is null. Commented Apr 6, 2017 at 18:50
  • @anubhava GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16) Commented Apr 6, 2017 at 18:51
  • @forkfork: Can you show your attempted code in question that is giving null output Commented Apr 6, 2017 at 19:02

1 Answer 1

1

You can use this script in BASH:

#!/bin/bash

n=50 # number of line to read every time

while read -r && arr=("$REPLY"); do
   # read n-1 lines using a for loop
   for ((i=1; i<n; i++)); do
      read -r && arr+=("$REPLY")
   done
   # call your script using 50 element array as argument
   bash ${DIR}/Downloader.sh "${arr[@]}" &
done < file
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.