I’m really new at using awk/sed
So, I have text file that is called performance.log that has following info
CPU 1 2 3 4 5 6
RAM 2 3 4 5 6 7
HAR 3 4 5 6 7 8
And with in the code in performance-eval.sh, function generates following info
Cur_CPU=10
Cur_RAM=11
Cur_HAR=13
I want to insert and save Cur_CPU,RAM,HAR to performance.log.
Cur_CPU will go to first row, second column
Cur_RAM will go to second row, second column
Cur_HAR will go to third row, second column
So that resulting performance.log would be
CPU 10 1 2 3 4 5 6
RAM 11 2 3 4 5 6 7
HAR 13 3 4 5 6 7 8
I’m not sure how to add 3 different values into 3 different columns.
Thanks for your help!
The easiest solution would be to use the
joincommand, but first you need to process the output of function that generates the additional info:We start by removing the
Cur_from the start of each line, then we replace=with a space character. Also, join expects both inputs to be properly sorted.The
-1 1argument tells join that for the first file, it should use the first field as a join field. Analogously,-2 1tells join that for the second file, it should use the first field too (in some implementations you could shorten into a single-N 1, so it uses the first field for both files).The join field is used as so: when join finds a line in the first file with the same join field as the line on the second file, the output contains the merged lines. Notice that the order of the files in the command line is important to the order of the fields in the final output.
Hope this helps =)