Path: sran124!katsu From: katsu@sra.co.jp (WATANABE Katsuhiro) Message-ID: Date: 27 Aug 90 17:29:51 Organization: Software Research Associates, Inc.,Japan In-reply-to: chrisb@risky.Convergent.COM's message of 24 Aug 90 18:43:45 GMT Newsgroups: comp.unix.questions Subject: Re: removing end of line mark with sed Distribution: comp References: <1990Aug19.194911.16628@fs-1.iastate.edu> <1990Aug19.234327.19785@iwarp.intel.com> <602@risky.Convergent.COM> # Sorry for my poor English. In article <602@risky.Convergent.COM> chrisb@risky.Convergent.COM (Chris Bertin) writes: > > | How do I remove the end of line marker from a stream? for example, > (cat $1; echo '\n_E_o_F_\n') | \ > sed -e ':top' -e '1,/_E_o_F_/ N' -e 's/\n/ /' -e 't top' -e 's/ _E_o_F_//' > > Note that: > sed -e ':top' -e '1,$ N' -e 's/\n/ /' -e 't top' > doesn't work because sed won't print lines that are not terminated by a > carriage return (bug?). Wrong. It is probable that unix standard sed doesn't take a (the last) input line that isn't terminated by a CR into pattern space. But, it isn't related to this question. The trouble of your second script is caused by `1,$ N'. `N' at $(last input line) will terminate sed processing immediately without printing pattern space. I think it is natural because sed neither can get any more input line nor can determine current line number after `N'. Do you approve of the line number `$+1' ? :-) (Gnu sed continues processing after `N' at $. QUIZ: How does it turn out? echo '' | GNUsed -e 'N' -e '=' And how? echo '' | GNUsed -e 'N' -e '=' -e 'N' -e '=' ) > If sed allowed addresses like '$-1', it would > make life simpler as well. Here is another way without _E_o_F_ (without `$-1', also) sed -e ':top' -e '$q' -e 'N' -e 's/\n/ /' -e 'b top' As you all know, using `tr' is more easy and more reliable. There are some risks of buffer over flow in using `N' of unix standard sed. (Gnu sed will work fine, because it allocates pattern space dynamically.) For instance, you will miss some byte stuff if you apply above example to /bin/sh. (In case of /bin/sed on my Sony NEWS, it crashes and dumps core.) -- ----____----____ WATANABE Katsuhiro Software Research Associates, Inc. Japan. Not execute, but evaluate.