Replace specific column range in a non-delimited file with a string!

Hi All, I will need an help with respect to replacing a range of columns on a non-delimited file using a particular string pattern.

Say file input is

MYNUMBERD000000-BAN CHUE INSNTS       **    N+
MYAREDSDD000000+BAN CHUE INSNTS       **    N+
MYDERFFFSD00000-GIR PENT - ACH            **    N+
MYDDDDDAY000000+GIR PENT - ACH            **    N+

I have to replace the part from "+" or "-" to "**" with a string say "TEST".
I am specifically unable to traverse to 16th column and then replace from column17 to column38 with the string using sed.

So output should be as below :

MYNUMBERD000000-TEST**    N+
MYAREDSDD000000+TEST**    N+
MYDERFFFSD00000-TEST**    N+
MYDDDDDAY000000+TEST**    N+

Thanks for any help on this.

After 35 post here, you should now how to use code tags

awk '{gsub(/-.+\*\*/,"-TEST**");gsub(/\+.+\*\*/,"+TEST**")}1' file
MYNUMBERD000000-TEST**    N+
MYAREDSDD000000+TEST**    N+
MYDERFFFSD00000-TEST**    N+
MYDDDDDAY000000+TEST**    N+

Thanks a ton Jotne for the reply, but its giving quite a few error :

awk '{gsub(/-.+\*\*/,"-TEST**");gsub(/\+.+\*\*/,"+TEST**")}1' file.txt
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: illegal statement near line 1
awk: syntax error near line 1
awk: bailing out near line 1

I am using sun-os 5.1 for executing this script.
Sorry for missing the code tags.

Try to use /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk instead of awk

Thank you Jotne, it was getting executed via nawk.
I have a question though, can't we use

sed

to replace on

fixed column numbers, say colomn 21-40 to be replaced with some string(TEST)

.

As in future instead of +, - anyother symbol may come in, but the column lengths are always fixed.

I tried to google out the sed option to replace based on column number but couldn't fine one.

Thank you

sed 's/\([+-]\).*\(\*\*\)/\1TEST\2/' input_file

--ahamed

---------- Post updated at 06:09 AM ---------- Previous update was at 05:52 AM ----------

Using awk for specific columns

awk '{val=substr($0,21,19);gsub(val,"TEST",$0)}1' input_file

Note : 19 characters from position 21 which will cover from 21 to 40. So, you need to change it accordingly

HTH

--ahamed