Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!gem.mps.ohio-state.edu!apple!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.questions Subject: Re: tr Keywords: tr ascii Message-ID: <5233@omepd.UUCP> Date: 20 Nov 89 00:44:41 GMT References: <579@ncelvax.UUCP> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: usa Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 35 In-reply-to: cathy@ncelvax.UUCP (Cathy Benney) In article <579@ncelvax.UUCP>, cathy@ncelvax (Cathy Benney) writes: | Hello. I have been experimenting with "tr", the translate characters command. I am curious to know if tr can substitute from a single character in string 1 | to multiple characters in string 2. For example, could "tr" substitute | '\012' (the ascii new line) for '\015\012' (which would be ^M^J). I have been | trying this, using a command like: | tr '\012' '\015\012' < file.1 > file.2 | but without any luck. In the command above, tr substitutes ascii 012 for | ascii 015. What I would like is for tr to substitute every 012 with an | 012 015. I am a novice in using tr (could you guess?), so my approach may be | off, but I would appreciate any suggestions you may have. Thank you. Well, first, stock out-of-the-box 'tr' cannot do it. Tr knows how to delete chars, and replace chars, but not add chars. If you don't have Perl (shame on you!), use sed, as in: % sed 's/$/^M/' file.2 where ^M represents a *real* control-M, which you may have to futz around with the terminal escape chars to get it into the string. For example, under BSD unicies (UNIX plural :-), I can get a ^M by preceding it with a control-V. Another (nicer) solution (you knew it was coming...) is Perl, as in: % perl -pe 's/\012/\015\012/g;' which is typed just as you see it.... no magic chars. (Perl does all the magic. :-) Just another Perl hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/