I am trying to edit few lines of my file and create new file with all modifications
My lines are not in paragraph format, it looks something like this below,
R1 X XA 0i 1i H 0i
R2 X XA 1i 1i H 0i
R3 X XA 1i 1i H 0i
R4 X XA 1i 1i H 0i
R5 X XA 1i 1i H 0i
R6 X XA 0i 0i X 0i
They clearly don't have equal spacing between each item in row, but they are aligned column basis. I wand to edit R3 3rd item from XA to XAHBB but unable to maintain the column alignment
my $cur_line_num = 1;
while(<Sourcefile>){
my @RowEdit = split (" ",$_);
if($RowEdit[0]=~ m/^R3$/s){
$RowEdit[2]="RowEdit[2]HBB"
}
my $curr_line = join(" ", @RowEdit)
print $newfile "curr_line\n";
$cur_line_num++;
}
print "$cur_line_num\n";
My current output is as shown below
R1 X XA 0i 1i H 0i
R2 X XA 1i 1i H 0i
R3 X XAHBB 1i 1i H 0i
R4 X XA 1i 1i H 0i
R5 X XA 1i 1i H 0i
R6 X XA 0i 0i X 0i
Where as my expected output should look something like this below
R1 X XA 0i 1i H 0i
R2 X XA 1i 1i H 0i
R3 X XAHBB 1i 1i H 0i
R4 X XA 1i 1i H 0i
R5 X XA 1i 1i H 0i
R6 X XA 0i 0i X 0i
How to maintain column alignment while editing a file?