Except that you can't tell wget how to filter the urls to generate the filenames. I believe scott's solution is the best you can do. Besides, doing the network i/o is probably going to be the bottleneck anyway, not the shell loop.
Alternatively, you can stick with your original approach, which generates the undesirable filenames, and rename the files afterwards (perhaps with the rename utility).
In my opinion, scott's solution is preferable. Keep it simple.
[1] 14709
mv: missing destination file operand after `index.html?acc=OSR765454'
Try `mv --help' for more information.
-bash: filename1.gz: command not found
[1]+ Exit 1 mv index.html?acc=OSR765454
The & is a special character to the shell. The command is cut off at that point. So the shell takes everything before it as a command to run in the background.
[1]+ Exit 1 mv index.html?acc=OSR765454Exit 11
And then afterwards will run the following command:
file=filename1.gz filename1.gz
Which creates a variable named file with a value of filename1.gz intended for the environment of the command filename1.gz (which of course doesn't exist and so you get that command not found error).
To fix that mv command, quote any arguments with shell metacharacters. In your example, aside from the & , the ? is also special.
Don't blame this on me. I never suggested doing this. I merely mentioned that you could try using rename if you insisted on using wget -i . I suggested keeping it simple with scott's solution. I don't understand why you don't like that simple while-loop. Did you run it? If so, was it unacceptably slow? Did it give you an erroneous result?
And it works like a charm. Do you have a simple solution to do the above task in batch on all the files in the directory using rename? Because, I can't write the mv command for all those files in my directory. They are around 400 files. And the OSR number after acc= is varying. Can you suggest me something using sed and rename or sed and mv?
Why manually? In your original post you stated that you had the list of urls in a file. Is that not the case? Are you not now using that file as an option-argument thusly:
If so, just use this instead (I took the liberty of adding -r and quotes to scott's code):
I did that and all I see is a single output file instead of one. If all the 5 file sizes together is 10GB. I see a single file filename1.gz to be 10GB.