I have a fixed width file where the last line of the file needs to be checked at a certain position, and if value is found at that position, it is changed to another value specified by an ARRAY. The input file looks like this for the last line
210204154828000999990000056000000072328100000540000000
The values of interest are at position 27, 40 and 47. The values at those positions are 6, 1, 4 respectively. I'm using an ARRAY for checking these values. If the position of the ARRAY matches the value of the position, replace with the value of the ARRAY location. The code looks like this
#!/bin/bash
chars=( { A B C D E F G H I )
for num in "${!chars[@]}"
do
sed -i -E '$ s%^(.{26})$num%\1${chars[$num]}%' $1
done
I don't get a failure when running this but I don't see it updating the last line either. The expected output if this were working correctly would be the following:
21020415482800099999000005F000000072328A000005D0000000
The command to execute is as follows
# ./convert.sh file1.txt
I'm sure something is wrong with my sed but I just can't figure it out. Any help would be appreciated.