Replace specific positions in a file

I have a fixed-length positional file. I am trying to replace content of position 4-13 (length=10) with xxxxxxxxxx.
Sample 2 rows in this file:

H0187459823  172SMITH, JOE
H0112345678  172DOE, JANE

In this example 87459823 (from 1st line) and 12345678 (from 2nd line) (both in position 4-13) would be replaced with xxxxxxxxxx

Any help is much appreciated.

1 Like

Here is a way to play with awk

akshay@db-3325:/tmp$ cat file
H0187459823 172SMITH, JOE
H0112345678 172DOE, JANE

akshay@db-3325:/tmp$ awk '{print substr($0,1,3)"<put_your_string>"substr($0,13)}' file
H01<put_your_string>172SMITH, JOE
H01<put_your_string>172DOE, JANE
2 Likes

Welcome to the forum.

Please always show your OS, shell, and preferred tools' versions, so the solutions proposed will match your setup.
And, add code tags around code and data as required by forum rules.

Any preferred tools?

Mayhap my arithmetics are wrong, but 12345678 and 87459823 cannot fill character positions 4-13?

thank you. it worked.

--- Post updated at 07:23 PM ---

Sure. Thank you. Will do.
By the way In my example above both numbers have trailing spaces of 2 characters which makes each of length 10.
Starting position, for both lines, is 4 and ending position is 13 (includes 2 spaces at the end).

1 Like