You could HIT THANKS button left most corner of any post if you feel it helped you . Now coming to your problem, no need to use a loop for this. There could be 2 situations for this.
1st: To substitute all the string keywords in file1 in that case following may help you.
Above will change them as per file2's line number so let's say string keywords comes on 1st, 3rd line of file1 so it will substitute string keyword with respective line's value from file2 in file1.
2nd: In case you want to give multiple values of line numbers which you want to change in file1, then following may help you.
So in this case line number(s) 1st and 4th from file2's value will substituted on file1's keyword string . Also it will not bother line number on file1 side(asap a string (string) comes it will substitute it).
Thanks but it is not working. With this script, the replacement takes place in the second field of the four 4th lines of the files, and all other 2nd fields of the remaining lines are removed.
I need to mention that there are lines above and below the strings I need to replace.
1st: You want to do replacement wherever string keyword is found on lines of Input_file1.
2nd: I am assuming that in case number of lines are lesser in Input_file2 than Input_file1(means keywords strings are coming more than the numbers in Input_file2) then once it reaches it last value(from Input_file2) then again it should start from beginning in Input_file2 values.
This works. I have another file 1 with content:
...
set title "XXX YYY I = 3 mol L^{-1} pH = string1"
...
set title "XXX YYY I = 2 mol L^{-1} pH = string2"
...
set title "XXX YYY I = 1.5 mol L^{-1} pH = string3"
...
set title "XXX YYY I = 1 mol L^{-1} pH = string4"
...
With your actual script, the output is:
...
set 3.333
...
set 4.251
...
set 1.121
...
set 5.456
...
I would like to obtain the following output please:
...
set title "XXX YYY I = 3 mol L^{-1} pH = 3.333"
...
set title "XXX YYY I = 2 mol L^{-1} pH = 4.251"
...
set title "XXX YYY I = 1.5 mol L^{-1} pH = 1.121"
...
set title "XXX YYY I = 1 mol L^{-1} pH = 5.456"
...
Thanks in advance.
I have another file 2 with content:
3.333 #3M
4.251 #2M
1.121 #1.5M
5.456 #1M
With the actual script, the output is:
...
set title "XXX YYY I = 3 mol L^{-1} pH = 3.333 #3M"
...
set title "XXX YYY I = 2 mol L^{-1} pH = 4.251" #2M"
...
set title "XXX YYY I = 1.5 mol L^{-1} pH = 1.121 #1.5M"
...
set title "XXX YYY I = 1 mol L^{-1} pH = 5.456 #1M"
�
Please, is it possible to adapt the script to get:
...
set title "XXX YYY I = 3 mol L^{-1} pH = 3.333"
...
set title "XXX YYY I = 2 mol L^{-1} pH = 4.251"
...
set title "XXX YYY I = 1.5 mol L^{-1} pH = 1.121"
...
set title "XXX YYY I = 1 mol L^{-1} pH = 5.456"
�
Please do wrap your samples in CODE TAGS(see how my command looks similarly see co de button while editing your post and wrap your examples in it). Could you please try following then and let me know if this helps you.