I've got an output file that's already gotten the following values in it

```
16.1
144.3
352.5
23.4
129.5
993.9

```

I've also got a source file with the following text in it.

```
#0  abc 2016-08-06 01:12:57 AM  9.1%    779.9M of 1G    156.3M of 1G
#1  abc 2016-08-06 02:33:47 AM  12.1%   339.9M of 1G    126.3M of 1G

```

Using grep, I run a loop over the #0 and #1 lines and store the following in variables on the first iteration.

```
$cpu #stores 9.1
$mem #stores 779.9
$disk #stores 156.3

```

The next time, my grep loop runs over the "#1" line, my 3 variables will update to 12.1, 339.9 and 126.3.

I'm trying to use sed to get the output as follows 

```
16.1,9.1
144.3,779.9
352.5,156.3
23.4,12.1
129.5,339.9
993.9,126.3

```

I'm using the following sed code in a loop to do this.

```
sed ""$counter"s/$/,"$cpu"/" "$opFile" | tee "$opFile"
((counter++))
sed ""$counter"s/$/,"$mem"/" "$opFile" | tee "$opFile"
((counter++)
sed ""$counter"s/$/,"$disk"/" "$opFile" | tee "$opFile"

```

The reason why I'm using tee is because without it, I get the output like so when run in a script

```
16.1,9.1
144.3
352.5
23.4
129.5
993.9
16.1
144.3,779.9
352.5
23.4
129.5
993.9

```

and so on.. I hope you see what's happening. 

Tee provides me the right answer but only works sometimes but with very odd behaviour. On the command line, sometimes it appends to all 6 lines correctly. Another time, it appended to 5 lines and then just made the opFile empty. And another time, on the first try itself it made the opFile empty. Forget command line, at the end of executing my script, everytime my opFile is blank.

Why does this happen?