I am trying to use sed to replace specific characters at a specific position in the file with a different value... can this be done?
Example:
File:
A0199999123
A0199999124
A0199999125
Need to replace 99999 in positions 3-7 with 88888.
Any help is appreciated.
Can you show us what you have tried so far?
Regards
I have tried several variations of sed with no luck.
sed 's/...99999/88888/'
This was close except it replaced the first 8 characters with only 5.
-----Post Update-----
Nevermind, I got it.
sed 's/^\(.\{3\}\)99999/\188888/'
Replaces 99999 starting at position 3 with 88888
sed 's/\(.\{3\}\)\([0-9]\{5\}\)\(.*\)/\188888\3/g' filename
-Devaraj Takhellambam
can sed do this beyond 255 chars ? for example, i want to replace at position 500.
Scott
6
Hi.
Sed will read a line of any length, but the command block { } has a 32K -1 limit (32767) (this may be implementation-specific)
# sed "s/\(.\{32767\}\)...../\1 XXXXxxxX/" file1 > file2
# echo $?
# 0
# sed "s/\(.\{32768\}\)...../\1 XXXXxxxX/" file1 > file2
sed: -e expression #1, char 34: Invalid content of \{\}