Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

replacing fixed strings

Status
Not open for further replies.

jescat

Technical User
Jul 29, 2004
32
US
I have a question of how to replace a string at a static starting position and length with another string. For example in the following example of text how would I replace "hello" with five spaces.

12hello89

Note hello will always start in position 3 with length 5.

I can get sub or gsub to work because is wants a regexp not a string positons like substr

Anyhelp would be appreciated
 
You could use
Code:
s2 = substr(s1,1,2) "     " substr(s1,8)
Hope this is helpful. CaKiwi
 

yeah, that's too bad one cannot do sed's anchoring with
s/^\(..\).....\(.*\)$/\1 \2/g

I always wish there was something like that in awk....

vlad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top