BASH - How to combine data from 2 files
I have 2 files with the following data
file1
:
datapoint1name##datapoint1name
datapoint1name.PercentUtilization=
datapoint2name##datapoint2name
datapoint2name.PercentUtilization=
datapoint3name##datapoint3name
datapoint3name.PercentUtilization=
file2
:
74.5
64.9
48.5
How can I achieve this in a single file?
datapoint1name##datapoint1name
datapoint1name.PercentUtilization=74.5
datapoint2name##datapoint2name
datapoint2name.PercentUtilization=64.9
datapoint3name##datapoint3name
datapoint3name.PercentUtilization=48.5
I'll have an indefinate amount of datapoints in this file but the structure here will remain constant.
sed 's/^/\n/' file2 | paste -d '' file1 -
(Note: there is nothing specific to Bash in the above command.)
At first sed
injects empty lines into data from file2
. Then paste
appends the result to the lines from file1
.
The empty lines come from sed
as the 1st, 3rd, 5th line, etc., they are appended to odd lines from file1
so these lines don't change. The actual lines from file2
come from sed
as the 2nd, 4th, 6th line, etc., they are appended to even lines from file1
.