BASH: replace strings in on file by the strings in another one
Dear Experts,
I have two files. One with lines: Code:
{{2.9,17},{136.178,117.917,333.375},{FRAC}}, Code:
-39.1562 49.1725 55.4316 So, the output file should look like: Code:
Any answer would be appreciated. Thanks a lot! |
Yes, awk can do the trick:
Code:
awk '{getline line < "file2"; gsub(/ /,",",line); sub(/FRAC/,line); print}' file1 |
Quote:
Code:
{{5.1,26},{317.814,97.393,345.404},{-21.99705,2.48297,19.17858,}}, What I really need is: Code:
{{2.9,17},{136.178,117.917,333.375},{-39.1562,49.1725,55.4316}}, |
This is because the second file has an extra space at the end of the lines, so that they are substituted with a comma by the gsub function. You can try to add another gsub to remove them before doing the substitution, e.g. (see the part highlighted in red)
Code:
awk '{getline line < "file2"; gsub(/ +$/,"",line); gsub(/ /,",",line); sub(/FRAC/,line); print}' file1 |
Quote:
Just one more question, could you explain what the meaning of the regular expression in Code:
gsub(/ +$/,...) Thanks!!! |
Quote:
Code:
/ +$/ Quote:
|
All times are GMT -5. The time now is 11:57 PM. |