ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a variable (call it $valAS) that gets calculated . Also, i have a files Bassu3. if $valAS= 45368 (2nd part of 2nd line in Bassu3) after calculation, then $result=45368, but if $valAS != 45368 then $result= $valAS
Bassu3:
Quote:
name.srv
name 45368 (value always changing)
name 99999
name 88888
let's say always result=$varAS. But a new condition must be added to this. the condition is if $valAS= 45368 (2nd part of 2nd line in Bassu3) then result=45368, but if $valAS != 45368 then result= $valAS. so i need to know if $valAS is equal to 2nd part of 2nd line in Bassu3,or not.
So if the 2nd part in 2nd line in file Bassu3 is not equal to valAS then result= 2nd part in 2nd line in file Bassu3 Not $varAS
Hmmm ... seems more of the same to me. I do understand basically you want an if statement, what I am asking is, what are you having problems with?
I think it was explained before, but if not I will again. Not only do you need to ask your question about what you want to do, but you also need to supply what you have tried
and where you are stuck so that we can help. Otherwise we do the work and you don't learn what you need to. Then you come back again because you have not furthered
your knowledge.
Let me help a little:
1. You would like to write a script
2. You would like script to test the second value on the second line of a particular file
3. You would like to write an "if" statement that sets a variable based on the item found in step 2
If I am wrong, please correct me.
If I am right, use this pseudo code to write the script and let us know when you get stuck
I appreciate your comments. please note i "do" the work never want to drop the load or run away from unknown. that's the main reason i have accepted to start & FINISH this project - even i have NO KNOWLEDGE about Bash- in addition to my other responsibilities ..... Anyway, i am sorry if i look like someone wants to take advantages of your kind help.
ok ... firstly, I didn't mean to sound like I was pointing a harsh finger. Just it is easier if we know where you are coming from
So let us look at your code:
1. The default field separator for awk is a space so your -F" " is not required.
2. Unless a freak accident were to occur that the file is updated between calls to awk, it would be impossible for either variable to not be equal. In saying that, I am not sure if you just wanted to test if your "if" works??
4. And this one is important when saying you have an error, show us the error There are many that are possbile and sometimes simply looking at your code will not provide what might have gone wrong.
Find out why i have the error. the value of $2ndline & $vara are in 192.168.0.1 format. somehow it does not like this format. i must find a way to ignore the dots. tried with cut it works but i have to cut each dot, so i have to cut 8 times which is so long to do that.
Find out why i have the error. the value of $2ndline & $vara are in 192.168.0.1 format. somehow it does not like this format. i must find a way to ignore the dots. tried with cut it works but i have to cut each dot, so i have to cut 8 times which is so long to do that.
any ideas??
bash has no problem with having the likes of 192.168.0.1 as variable values. The problem is in the format of your if command, specifically the test. Clues here.
Thanks for your attention catkin. please note when i use "cut" my statement works find, but when i use if with my variable it does not. i have done a test at the command line with if and 192.168.0.1 got error. but when i use 19216801 i get the result.
please try & let me know the final result.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.