in this example there are six keywors present (Gateway, Hostname, IP_Address,Netmask,Primary_DNS,Seconday_DNS). sometimes user may fill only 4 fileds then there will be only four keywords.
what i am looking for is, if the keyword Gateway is present in the file test, append its corresponding value with the keyword (here Gateway=3.3.3.3 ) to test1 . Hostname is present, it should appned the value h ostname=test.test.com to test2 . Like that for all the keywords.
If you have any other requirements then kindly let us know all in all conditions with full details(with sample Input_file and expected output in code tags) please.
as i mentioned in the question, there are six keywors present in this examplle (Gateway, Hostname, IP_Address,Netmask,Primary_DNS,Seconday_DNS). sometimes user may fill only 4 fileds then there will be only four keywors present in test. what i am looking for is if the keyword gateway is present anywhere in the file then append Gateway=3.3.3.3 in test1. like that for all keywords. if some keywords are not present it wont append anything
So above approach will create always line which have Gateway in it to file name test1 and so on always, if you want to append the data(let's say you have multiple line like you shown into your Input_file) then you could change > to >> to append it in above code.
If any string is NOT present in a Input_file then it will NOT increase the value of variable I, so let's say Gateway line is going to file named test1 and then Netmask should go to test3 BUT if in between IP_Address is not found then Netmask one will go to test2 then.
Let's say your Input_file have multiple occurrences of strings which you have mentioned above and you want to keep the files from test1 to test6 only so this code will help you to do so and it will keep appending the lines into their respective files.
Firstly you could THANK a person by using THANKS button on each post's LEFT most corner, secondly you should use code tags as per forum rules for sample Input_file or sample outputs. Could you please try following and let me know if this helps(I am taking my 3rd approach in previous post, if you need any other one you could try to edit it).