Help with Complex Awk.

Hi,
I have a file. In this file when ever the word "ABC" occurs at position from 25 and 34 I would like to replace
the value at postion 100 to 5 for the first 1000 rows only.

I have written the following Awk command.

 
nawk 'substr($0,25,9)=="ABC" {print $0}'  filename

The above command will not work properly as i am checking for ABC. But the length of the string i am checking is 9 characters.so the remaining will be spaces.
So I need to add some kind of trimming logic and also to figure out a way to track first 1000 records where the value is ABC and then replace the position 100 with value 5.

Help is appreciated.

nawk 'NR<=1000{s=substr($0,25,10);if (s~/ABC/) $0=substr($0,1,99) "5" substr($0,101);print $0}' infile

I haven't tried it but maybe it could work

nawk 'NR<=1000&&substr($0,25,10)~/ABC/{sub(substr($0,1,100),"5");print}NR>1000||substr($0,25,10)!~/ABC/{print}' infile

Pos. 25 - 34 is 10 chars. Try this simple code:

nawk 'BEGIN{FS=OFS=""} NR<=1000 && substr($0,25,10)~/ABC/ {$100="5"}1'  filename

All,

All the replies looks good to me except the fact that all of them consider the first 1000 rows (NR<=1000) for replacement. But the first 1000 rows that i am expecting to replace are the onces that have "ABC" between 25 and 34 character.

Say the 1000 rows containing "ABC" are records numbers
1001
2001
3003
4005 like that
in this case NR<=1000 will not work.