My file looks like this:
Scenario 1 0.20 0.00 0.00 r
Scenario 2 0.08 0.34 & 0.34 r
Scenario 3 6 12.95
Scenario 4 0.00 0.08 0.00 0.00 & 0.35 r
Scenario 5 0.07 0.08 & 0.42 r
Scenario 6 6 8.70
Scenario 7 0.00 0.07 0.00 0.00 & 0.42 r
Scenario 8 0.31 0.28 & 0.70 f
Scenario 9 5 5.06
My objectives is: To replace columns with empty cells/spaces/absent values with "-" (there are a total of 8 fields)
The problem I'm facing while using the awk command to do this is that the field separator keeps changing with every line.
What I've done so far: I've extracted the lines which have certain field patterns and placed them in different files. Eg: I have placed Scenario 3,6 and 9 in one file and the rest in another file to make it easier to work on the data. What I have now is:
File 1:
Scenario 3 6 12.95
Scenario 6 6 8.70
Scenario 9 5 5.06
File 2:
Scenario 1 0.20 0.00 0.00 r
Scenario 2 0.08 0.34 & 0.34 r
Scenario 4 0.00 0.08 0.00 0.00 & 0.35 r
Scenario 5 0.07 0.08 & 0.42 r
Scenario 7 0.00 0.07 0.00 0.00 & 0.42 r
Scenario 8 0.31 0.28 & 0.70 f
Expected output:
Scenario 1 - - 0.20 - 0.00 0.00 r
Scenario 2 - - 0.08 - 0.34 & 0.34 r
Scenario 3 6 12.95 - - - -
Scenario 4 - 0.00 0.08 0.00 0.00 & 0.35 r
Scenario 5 - - 0.07 - 0.08 & 0.42 r
Scenario 6 6 8.70 - - - -
Scenario 7 - 0.00 0.07 0.00 0.00 & 0.42 r
Scenario 8 - - 0.31 0.28 & 0.70 f
Scenario 9 5 5.06 - - - -
Case 1(using awk with FIELDWIDTHS):
$ awk 'BEGIN { FIELDWIDTHS="37 3 7 7 7 9 9 "} {for(i=1;i<=NF;++i){printf $i"|"};print""}' main1.txt
| I_BLENDER_0/R_137/CLK (SDFFX2_HVT) | | | 0.20 | | 0.00 | 0.00 r
| I_BLENDER_0/R_137/Q (SDFFX2_HVT) | | | 0.08 | | 0.34 & | 0.34 r
| I_BLENDER_0/n2757 (net) | 6 | 12.95|
| I_BLENDER_0/U4847/A1 (AND2X1_LVT) | | 0.00 | 0.08 | 0.00 | 0.00 & | 0.35 r
| I_BLENDER_0/U4847/Y (AND2X1_LVT) | | | 0.07 | | 0.08 & | 0.42 r
| I_BLENDER_0/n2616 (net) | 6 | 8.70 |
| I_BLENDER_0/U1/A4 (NAND4X0_HVT) | | 0.00 | 0.07 | 0.00 | 0.00 & | 0.42 r
| I_BLENDER_0/U1/Y (NAND4X0_HVT) | | | 0.31 | | 0.28 & | 0.70 f
Case 2(using sed command):
$ sed "s/^\(.\{,36\}\)$/\1`echo -$_{1..30}|tr -d '-'`/;
s/^\(.\{38\}\) /\1-/;
s/^\(.\{43\}\) /\1-/;
s/^\(.\{50\}\) /\1-/;
s/^\(.\{57\}\) /\1-/;
s/^\(.\{64\}\) /\1-/;
s/^\(.\{73\}\) /\1-/;
s/ *$//"
I_BLENDER_0/R_137/CLK (SDFFX2_HVT) - - 0.20 - 0.00 0.00 r
I_BLENDER_0/R_137/Q (SDFFX2_HVT) - - 0.08 - 0.34 & 0.34 r
I_BLENDER_0/n2757 (net) 6 12.95
I_BLENDER_0/U4847/A1 (AND2X1_LVT) - 0.00 0.08 0.00 0.00 & 0.35 r
I_BLENDER_0/U4847/Y (AND2X1_LVT) - - 0.07 - 0.08 & 0.42 r
I_BLENDER_0/n2616 (net) 6 8.70