Thanks to all who posted so many solutions to me,
Paradoxically, there is no simple solution with "sed"
The most appropriate one was suggested by James Sainsbury
<sainsb_j_at_chem.usyd.edu.au>:
awk '{ gsub(/\octal_code/, "string"); print $0 }' myfile
An interesting one (but a little more dangerous) by Joerg Bruehe
[joerg_at_sql.de]
tr '\octal' 'X' < myfile | sed s/X/string/
where X is an ASCII character not used in the text file
And at last a perl and C solution by system administration account
[sysadmin_at_astro.su.se]
perl -pe 's/\octal_code/string/g' myfile
-----------
#include <stdio.h>
#define OCTAL_CODE 0xNNN
#define MY_STRING "my_string"
int main(void) {
int c, sts;
for (c=getchar(); c!=EOF; c=getchar()) {
if (c == OCTAL_CODE) sts = puts(MY_STRING);
else sts = putchar(c);
if (sts == EOF) {
perror("write");
return 2;
}
}
if (ferror(stdin)) {
perror("read");
return 1;
}
return 0;
}
-----Message d'origine-----
De: ROBIN Jean-Marie (EURIWARE S.A.)
Date: vendredi 9 mars 2001 17:01
À: tru64-unix-managers_at_ornl.gov
Objet: how to substitute a no printable character by a string in a text
file
Hello Managers,
I want to substitute in a file a no printable character by a
multi-characterstring, as something like that:
sed s/\octal_code/"my_string"/g myfile
sed does not like this syntax and I can't use tr, because my string is
multi-character...
Any suggestions?
ATTENTION :
Si vous n'êtes pas destinataire de ce message, vous n'êtes pas autorisé à copier, retransmettre, distribuer, révéler ou conserver le contenu de ce message.
WARNING :
If you are not the intended recipient, you are not authorised to copy, disclose, distribute or retain in this e-mail.
Received on Mon Mar 12 2001 - 09:27:56 NZDT