Sed parsing error

I'm having a problem with a sed script.

A programmer needs to change columns 942,943,944 to blank spaces only where it has the number 999 in every line.

I didn't have a copy of the data file to test with originally so made my own up with a bunch of x's and put 999 in columns 5-7. The sed worked.

Today, I got a copy of the real data file, changed the �4' to �941' to reflect the actual starting column and the script fails with :

---

# ./sed_test

#!/bin/ksh -xv

#

sed -e 's/^\(.\{940\}\)999/\1 /' /admin/bin/test/PGINPEN > /admin/bin/test/sed.test.data.out

+ sed -e s/^\(.\{940\}\)999/\1 / /admin/bin/test/PGINPEN

+ 1> /admin/bin/test/sed.test.data.out

sed: 0602-404 Function s/^\(.\{941\}\)999/\1 / cannot be parsed.

___
It doesn't like the starting column for some reason.

Here are the 2 scripts I used.

sed -e 's/^\(.\{4\}\)999/\1 /' /admin/bin/test/sed.test.data2 > /admin/bin/test/sed.test.data.out

sed -e 's/^\(.\{941\}\)999/\1 /' /test.input.file > /test.output.file

Any ideas?

Hi.

The count appears to be too large for some versions of sed.

I created a file containing a line of 1002 characters. Using sed, I added an "A" after 944 characters and it worked without error with GNU sed on Linux.

On Solaris, the same command:

sed -e 's/\(.\{944\}\)/\1A/'

produced:

sed: command garbled: s/\(.\{944\}\)/\1A/

I used:

sed -e 's/\(.\{4\}\)/\1A/' $FILE

and it worked correctly. Also at 44, 244, but failed at 344. It works at 255, and fails at 256. (Those powers of 2 will get you every time :slight_smile: )

The version I have on SunOS 10.5 is:

sed - ( /usr/xpg4/bin/sed Aug 9 2005 )

Perhaps an awk script might work ... cheers, drl