0

I have a line in bash file like ---

curl -L $domain/url1 options

domain is already read from another text file and domains like

abc.com
google.com
yahoo.com

and i have another separate file which contains further URL (lot in number):

url1
url2
url3
....
url1000

I want to replace that url and append that like:

curl -L abc.com/url1 options
curl -L abc.com/url2 options
curl -L abc.com/url3 options
....
curl -L $abc.com/url1000 options

It is taking too much time manually, so I want to automate this process.

1 Answers1

2

Use a proper loop in bash with Process-substitution,

while IFS= read -r url; do
    curl -L abc.com/"$url" options
done <url_file

would just be sufficient (or) in a single-line of the same-loop,

while IFS= read -r url; do curl -L abc.com/"$url" options; done <url_file

For your updated requirement to loop on two files, you need to define multiple file descriptors and read from it,

while IFS= read -r domain <&3; do
    while IFS= read -r url <&4; do
        curl -L "$domain"/"$url" options
    done 4<url.txt
done 3<domain.txt

The above should work fine on any POSIX shell not involving any bash-isms, you could just put the above in a script with a #!/bin/sh she-bang.

Inian
  • 80,270
  • 14
  • 142
  • 161
  • your answer is right in normal context ,, but i am reading abc.com from already a text file that in url_file – user7423959 Apr 02 '17 at 07:11
  • 1
    @user7423959: You didn't mention that as part of the question. So you have two files, reading from each file on each iteration. Please provide samples of those files – Inian Apr 02 '17 at 07:13
  • 1
    @user7423959, wouldn't that be a relevant detail for the question? – Stephen Rauch Apr 02 '17 at 07:13
  • 1
    @Inian, no, he should go ask another question. You provided a fine answer to his question, you should not have to do it again. – Stephen Rauch Apr 02 '17 at 07:14
  • not a problem , i will approve this answer right ,, if i not gotta any other . – user7423959 Apr 02 '17 at 07:18
  • yup a lot entries , more than 400-500 – user7423959 Apr 02 '17 at 07:21
  • @user7423959: Refer my update, it should work for automating two files at once – Inian Apr 02 '17 at 07:23
  • actually wants a little bit help of you on same question for multithreading if you can . – user7423959 Apr 05 '17 at 13:01
  • http://stackoverflow.com/questions/43221004/proper-use-of-and-wait-in-bash-for-mutitasking – user7423959 Apr 05 '17 at 13:02
  • @user7423959: This is not the standards of SO, every question is meant to be answered within its scope. This question was earlier asked and accepted. It is not recommended to ask an extension or a totally new question. New questions need to asked as per the asking guidelies. – Inian Apr 05 '17 at 13:02