I have a file called list which has something like
1.html
2.html
3.html
I want to run a curl command to read each line from the file and use it as a variable for curl, e.g.:
curl "xyz.com/v1/{input from each line of file}
Please help....
Try:
xargs -I{} curl "xyz.com/v1/"{} <file
For each line in your file
, this runs curl "xyz.com/v1/"
followed by the contents of that line.
To illustrate what happens, without downloading anything, we can add an echo command:
$ xargs -I{} echo curl "xyz.com/v1/"{} <file
curl xyz.com/v1/1.html
curl xyz.com/v1/2.html
curl xyz.com/v1/3.html
Note that I left the base URL, xyz.com/v1/
, in double-quotes as it was in the question. That means that it is subject to shell expansions. If you don't want that (and you likely don't), then use single-quotes:
xargs -I{} curl 'xyz.com/v1/'{} <file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With