-1

How to loop a wget command in bash shell with URL parameters from a file.

File is space delimited :

$ cat parameters.txt
ANLA 830093 37227 2018/12/23 C14111
ANLA 2647724 106308 2018/12/23 C301205
BEDER 2638573 94596 2018/12/12 INDISP
.....

URL resquests use get method so I would like to to set parameters from a line and build URLs with them.

$ for i in (cat parameters.txt);  .. ? setting $p1,$p2,$p3,$p4 ? .. ;wget -qO- "http://example.com/planning.dll?Id=$p1&Prest=$p2&Time=$p3&Date=$p4" | ..processings ... >>output.txt; done

Parameter expansions ${....} should be the clue but how ? Or other answer ?

I'd like a way like cut -d " " -f "colomn" file command for variables.

1 Answers1

1

First, make sure you know how to loop over lines of a file in bash and Why don't read lines with for.

Use while read ....


Besides that, I would use read -a to parse the parameters into an array:

while read -r -a p ; do
    echo wget  -qO- "http://example.com/planning.dll?Id=${p[1]}&Prest=${p[2]}&Time=${p[3]}&Date=${p[4]}"
done < parameters.txt

(Remove the echo in front of wget when you are ok with it)

hek2mgl
  • 152,036
  • 28
  • 249
  • 266