Im using sed on an AIX machine. I am trying to change the 137-139 characters if they are a ' 36'/'000' to a '036'. The positions that need to be changed are fixed.
the source data that I have is
$cat v.txt
4000422985400050462239065593606500000007422985707771046154054910075641MC0318AMWAY OF AUSTRALIA CASTLE HILL AU 5599 0000000097950007077Y10001 6022100000 0 0
4000422985400050462239065593606500000007422985707771046154054910075641MC0318AMWAY OF AUSTRALIA CASTLE HILL AU 5599 000000009795 367077Y10001 6022100000 0 0
4000422985400050462239065593606500000007422985707771046154054910075641MC0318AMWAY OF AUSTRALIA CASTLE HILL AU 5599 0000000097954367077Y10001 6022100000 0 0
I am using the below command which I got from this forum
sed -r -i.Original '/^4000/s/(.{136}) 36|000/\1036/' file
You are using GNU sed syntax. -i means 'in place' the -i.Original is a suffix to add to a tmp file so you can get your old file back if there was an error. -r is also not standard.
what confuses me is why are the characters are positions 143,144 and 145 changing when i think the above AIX sed code only replaces characters at positions 137-139
What we forgot to mention in the other thread is that when you use 000 instead of ... then you need to use an anchor for the beginning of the line in the form of a caret ( ^ ), otherwise it will try to match 000 with 136 arbitrary characters before it ..
--
Further, alternation is not part of regular sed (which uses BRE, basic regular expressions), instead try specifying the substitution twice:
sed '/^4000/{s/^\(.\{136\}\)000/\1036/; s/^\(.\{136\}\) 36/\1036/;}' file
---
Alternation would have worked with GNU sed with the -r option (or BSD sed with the -E option) that allows the use of extended regular expressions (ERE), which does have alternation, but GNU sed is usually not present as standard on AIX.
Try: