tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: "ROBIN Jean-Marie \(EURIWARE S.A.\)" <jmrobin () euriware ! fr>
To: tru64-unix-managers
Subject: SUMMARY: how to substitute a no printable character by a string i	n a
Date: Mon, 12 Mar 2001 09:26:22 +0000	[thread overview]
Message-ID: <98438924223878.tru64-unix-managers.marc@archive.invalid> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1845 bytes --]

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@chem.usyd.edu.au>:
	awk '{ gsub(/\octal_code/, "string"); print $0 }'  myfile

An interesting one (but a little more dangerous) by Joerg Bruehe
[joerg@sql.de]

	tr '\octal' 'X' < myfile | sed  s/X/string/=20
	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@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=3Dgetchar(); c!=3DEOF; c=3Dgetchar()) {
	        if (c =3D=3D OCTAL_CODE) sts =3D puts(MY_STRING);
	        else sts =3D putchar(c);
	        if (sts =3D=3D EOF) {
	            perror("write");
	            return 2;
	        }
	    }
	    if (ferror(stdin)) {
	        perror("read");
      	  return 1;
    	}
    	return 0;
	}





-----Message d'origine-----
De: ROBIN Jean-Marie (EURIWARE S.A.)=20
Date: vendredi 9 mars 2001 17:01
=C0: tru64-unix-managers@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.

                 reply	other threads:[~2001-03-12  9:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox