I am trying to develop a shell script on AIX 5.3.5 / ksh or ksh93, which will take a text file with fixed-length rows ('records'), and on each row replace certain characters, based on position, with spaces.
For example, I may want to replace characters 450 through 470 with 20 blank spaces.
Problem I've encountered is that most unix utilities are based on delimited fields, not position-defined fields. I've tried to cludge it in with regexes:
CTC_PS_BLANKCMD="sed s/^\(.\{$CTC_PS_BEG\}\)\(.
\{$CTC_PS_
LEN\}\)/\1
$CTC_PS_SP
ACER/ $CTC_PS_SOURCE"
(where CTC_PS_BEG is the first character to be replaced, CTC_PS_LEN is the length, CTC_PS_SPACER is the string with spaces, and CTC_PS_SOURCE is the input file).
However, two problems: no matter how I play with quotes, interpreter/shell changes the number of spaces to single; more over, it only works for characters up to 255, because of AIX limit of RC_MAX_DUP which I cannot change - it only allows up to 255 matches of a regular expression.
What is the best way I can create a command that will replace characters based on position?
Start Free Trial