Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site bcsaic.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!houxm!mtuxo!mtunh!vax135!cornell!uw-beaver!fluke!ssc-vax!bcsaic!michaelm From: michaelm@bcsaic.UUCP (michael b maxwell) Newsgroups: net.unix Subject: Putting in newlines using sed Message-ID: <376@bcsaic.UUCP> Date: Fri, 15-Nov-85 13:29:19 EST Article-I.D.: bcsaic.376 Posted: Fri Nov 15 13:29:19 1985 Date-Received: Mon, 18-Nov-85 07:28:49 EST Organization: Boeing Computer Services AI Center, Seattle Lines: 50 This is on BSD 4.2... I have a process putting out lines that look something like this: fjlkjf foo (a b c) jflkjf (jfkj) foo (x y a) fjjfj I want to break up the line so that each "foo" followed by its parenthesized list of arguments appears on a separate line. I don't care what happens to the other "words;" they are eliminated in later processing. My first thought was to use sed to do the ff: s/foo/^Mfoo/g -where "^M" is what I get by typing a ^V followed by a carriage return. What sed does with this is to substitute a ^M, i.e. a carriage return-- but no line feed. On the screen, the result is that you only see the last "foo" plus whatever follows it; all the rest are overprinted. And naturally this isn't what the following processes in the pipeline expect... So then I tried using to do the following: s/foo/^Jfoo/g Well, I couldn't get the ^J in there! I couldn't hide it from the shell with ^V, \, ', " or anything else I could think of (I even tried using vi to put it into a file of sed commands). As far as I can tell, there's no way of writing the s/... line above with a *real* linefeed in place of the ^ and J. Next, I tried ex. Now ex will put a linefeed in, rather than a carriage return, given the first s/... line above; but as far as I can see, ex can't edit a pipeline-- it only edits files (which is why sed exists, I imagine!). (You can get ex to send its output to a pipe, by doing %p.) What I finally settled on was to use sed to insert ^Ms, then tr to translate the ^Ms to ^Js (linefeeds). Can you say "kludge"? It works, but at the cost of quite a bit of overhead--the next step in the processing uses sed again, so the pipeline looks like: ... \ | sed (insert ^Ms) \ | tr (convert ^Ms to ^Js) \ | sed (command A; command B; command C...) \ | ... If I could eliminate the tr step, I could make "insert linefeed" be the first command that sed does, thus eliminating two processes. So far as I can say, there is no way of using tr to insert the ^Js in the first place. And no, we don't have rpl. If I ever have time to sit down and learn emacs, I'll probably find that I can use that, though I'm not sure it can edit a stream rather than a file. (Comments?) Any ideas? -- Mike Maxwell Boeing Artificial Intelligence Center ...uw-beaver!uw-june!bcsaic!michaelm