How to replace in an bash script variable?
This topic is a waste of time, no solution to the question.
Hello, im having urlfile and each url in it contains $ip variable which i need to replace by actual IP that is actual for the present "while loop" cycle: Code:
while read ip;do http://domain1.com/?something&?ipp=$ip http://domain2.com/?ipaddr=$ip&something=something http://domain2.com/?a=lldd?ipaddr=$ip#something But i dont know what is the clever/low resource usage/low amount of code way to replace that $ip variable inside the URLs that i have either in urlfile or in variable that i populate somehow out of urlfile? Thanks in advance ---- Update: Solution for my case: Quote:
|
Quote:
A brief Google search turns up lots. From just ONE is this sample: Code:
saveIFS="$IFS" |
yes, please anyone else how to do it please?
|
Quote:
|
Sorry, im newbie i do not understand your copy paste "solutions" that do not fits my case. That is why im asking for other people oppinion. I ask you to stop answering in my topics. If you do not provide solutions and instead you will be bashing offtopic & wasting my time and other readers time, i will just report your post.
|
Did you post the entire urlfile? And is it exactly as shown? Does the IP file and url file correspond one for one? Or as in your loop do you apply each IP to every URL?
|
Quote:
So far i have 3 URLs in urlfile and there are parts of that URLs, parts where should be IP assigned..: ...=$ip ...=$ip&... ...=$ip&... |
And the other questions?
Does the IP file and url file correspond one for one? Or as in your loop do you apply each IP to every URL? |
Quote:
So for each IP i will process all 3 URLs, and i need to replace the $ip variable in them by actual IP (actual for that "while loop" i mentioned in my initial post). Is it clearer please? |
Quote:
That, is how you stop being a 'newbie' and start to be able to do something for yourself. Quote:
Quote:
Quote:
Since you're a 'newbie' (who has been here 3 years), you probably haven't read the question guidelines. Quoting the relevant parts here, bolded parts are mine: Quote:
Quote:
|
I think string expansion by using the eval command should work but there are many ways.
I can not provide examples at the moment |
Quote:
In the first reply, I gave the OP something that would work, but they flat out said they didn't want to modify anything, and wanted a solution to 'fit their case' |
Things you do in a public forum:
- Be kind to each other - Be on topic - When you don't understand an answer ask for clarification, in the same way: If the question is not clear enough ask for clarification - Use all the options the forum software provides you. This includes the Ignore List function. Things you never do on a public forum (and even real life): - releasing private messages into public without explicit permission from all involved parties. There is a reason they are called private messages. If you feel you are harassed, insulted, ..., in private messages contact a mod or Jeremy. |
Please anyone else know the solution for this (see initial mesaage)? I cant believe it can be so difficult to come with simple, clever solution.
|
|
Quote:
This seems to dovetail nicely with your previous comment of "Im not looking to waste hours of time reading some technical data to get answer to my question." We WILL NOT write your script for you. Show effort of your own. |
That script was not helpfull alas.
|
Which script?
Did you look at the link I posted? |
Quote:
stringZ=abcABC123ABCabc echo ${stringZ//abc/xyz} But not sure how i can use it in my case. I already tried it, but it do not replace phrasse "$ip" by IP. I used something like: echo ${url//1.1.1.1/$ip} and echo ${url//$ip/1.1.1.1} but no change in variable |
Quote:
I have only one comment to this (see LQ rules) "That script was not helpfull alas." is not an acceptable answer. "your copy paste "solutions" that do not fits my case. That is why im asking for other people oppinion" is not an answer too. If you want to improve the quality of this communication (and obviously it is you who need a solution) you need to give some information about: what was wrong with that? Otherwise others will not be able to help you, because they (even me) have no idea how to give a better tip... |
pan64: i dont understand anything on one single script that was provided in this thread. Not sure how it can work in my case.
|
in that case ask how does this or that work, even line by line. Probably you will be able to modify it to fit your needs. But "repeating does not work" will not help
|
ok, then im asking for line by line explanation, if there is not any more simplistic way to achive what i want. i never thought it can be that difficult, wanted to learn some simple way.
|
Quote:
Sorry, the scripts provided WILL work, if you put any effort into them. If you actually posted something like "I modified the script in post #xxx, and gave it this input, but got this result, and I'm confused", you'd get help. Saying "it doesn't work" tells us nothing. And looking at the link michaelk gave you (after suggesting you look at it, they also had to look up a link for you), the sample script tells you exactly what you need to do...but you didn't do it. You're not following the syntax that's very clearly laid out in that document. And whether you like it or not, the FIRST REPLY (post #2), will work perfectly for you. It not only shows you how to read a file into an array, but how to process that array into variables (which is EXACTLY WHAT YOU WANT), then perform operations on that array...such as print them out, or do whatever you want with them. |
post reported & ignored, please be ontopic.
|
Quote:
Quote:
Code:
saveIFS="$IFS" IFS defines what separates the fields. In this case, a newline. Replace with whatever is your separator AGAIN...try reading the bash scripting tutorials. |
post not read and ignored as it do not provide any helpfull solution
|
what do you think, what will be really helpful - for you?
|
you do not know what is helpfull when you ask the question?
an answer that can help you solve the issue. prefferably example with comment on how that works. are you that stupid not to understand this. I hope i explained enough. And we can stop offtopic and time waste in this thread. If anyone of you do not wish to provide what i said, please be so kind and give me a favor to stay away from commenting in my topics and wasting everyones time. |
I'm afraid here, at LQ everyone is so stupid, they cannot understand you. Thanks for your valuable input.
|
I hope there will be someone who can help answer initial question.
update: i updated my initial post with solution i found myself. |
Quote:
Oh wait...I TOLD YOU about xargs in my VERY FIRST REPLY. Congratulations again on your efforts. |
Yes, your post was useless for me. Fortunatelly i was able to find ready made command my own way.
|
Quote:
|
Quote:
Grow up. You showed no effort here, any more than you have in many of your other threads. When asked for information and examples of YOUR OWN EFFORTS, you showed none, and get hostile. I received yet another nasty private message from you, despite me asking you EIGHT TIMES now not to message me any further. If you want someone to spoon-feed you an answer, with zero effort on your part, then just post things in the LQ Jobs forum, along with how much you'll PAY someone to do your work for you. Otherwise, if you have no interest in learning to stand on your own, and do things for yourself, there is no point in posting. |
i will not waste my time reading your stories sorry.
No, i have not used any of your comands knowingly as i ignored your posts except first one that had an script in it which i did not understood as mentioned. |
Quote:
Quote:
You're plain lazy. Period. Stop wasting peoples time here by asking for handouts like a beggar. Show effort, and we'll help you, as not only I have, but pan64, michaelk, and others in the MANY other threads you've opened, where you show no effort. Grow up. |
too long man )
if you need ot tell me something, please use PM, thanks |
Quote:
Want it shorter? You're a lazy bum, asking for handouts. Stop it. |
I am happy you found the answer...
Not sure what you did not understand in the link but here it is plus a similar method using sed. ip=1.2.3.4 url='http://domain1.com/?something&?ipp=$ip' newurl=${url/'$ip'/$ip} echo $newurl newurl=$( echo $url | sed "s/\$ip/$ip/" ) echo $newurl And go reread post #13 |
Quote:
|
Please get this thread back on topic. postcd, please read http://www.linuxquestions.org/questi...#faq_lqwelcome and let me know if you have any questions or need clarification. While LQ aims to be friendly and welcoming to all, you do need to be able to follow some minimal guidelines if you'd like to continue participating.
--jeremy |
This is the last reminder, for both, postcd and TB0ne: Be kind to each other. Don't insult each other. If you feel that the other part of the discussion is unable or not willing to understand you ask yourself if you want to use the Ignore List, a function of the forum software that is there for a reason.
The behavior that both of you have shown in this thread is not wanted here on LQ and if I see something like that in future postings of yours moderator action will follow. @TB0ne: I will ask Jeremy to look at your reports and to handle the situation. Since this thread is marked as solved and further discussion seems to lead nowhere it will be closed. |
All times are GMT -5. The time now is 03:48 AM. |