From bodec@Sherwood.co.uk Fri Sep 27 21:14:12 1996 Message-ID: From: Casper BodenCummins Subject: reversing a line in sed Date: Thu, 19 Sep 1996 14:59:40 +0100 X-Mailer: Microsoft Exchange Server Internet Mail Connector Version 4.0.837.3 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Path: fu-berlin.de!main.Germany.EU.net!EU.net!usenet2.news.uk.psi.net!uknet!usenet1.news.uk.psi.net!uknet!dispatch.news.demon.net!demon!mail2news.demon.co.uk Newsgroups: comp.editors X-NNTP-Posting-User: bodec@sherwood.co.uk X-Mail2News-Path: romford2.sherwood.co.uk Lines: 21 Al Aab asked a while back how to reverse a line in sed. I've come up with the following: sed -n ' s/$/@@/ : next s/\(.\)@@\(.*\)$/@@\2\1/ t next s/@@// p ' The @@ symbols are used as markers. Obviously I'd prefer to use \n if I could, but I can't see a generic way of doing so. It's something of a drawback that sed doesn't offer a marker in its repertoire. I'd be interested to hear from anyone with an answer to this problem. Casper Boden-Cummins. -- Join seders, the mailing for sed enthusiasts. Email Al Aab for details. From msb@sq.com Fri Sep 27 21:14:41 1996 Newsgroups: comp.editors Path: fu-berlin.de!news.th-darmstadt.de!uni-erlangen.de!news.dfn.de!news.ruhr-uni-bochum.de!news.rhrz.uni-bonn.de!news.rwth-aachen.de!genesis.westend.com!news.gtn.com!news.frankfurt.ecrc.net!news.ecrc.de!news.compuserve.com!chi-news.cic.net!arclight.uoregon.edu!nntp.primenet.com!cam-news-hub1.bbnplanet.com!news.mathworks.com!uunet!in3.uu.net!ott.istar!istar.net!tor.istar!east.istar!n2tor.istar!fastlane.ca!sq!msb From: msb@sq.com (Mark Brader) Subject: Re: reversing a line in sed Message-ID: <1996Sep20.110023.3030@sq.com> Organization: SoftQuad Inc., Toronto, Canada References: Date: Fri, 20 Sep 1996 11:00:23 GMT Lines: 25 > Al Aab asked a while back how to reverse a > line in sed. I guess I missed that. Let's see, \n as the marker is indeed the trick. The G command appends the empty hold space, *with its newline*, to the pattern space. Then you slide characters into place one at a time, and get rid of the extra newline. sed ' G : loop s/\(.\)\(\n.*\)/\2\1/ t loop s/\n//' Demonstration: .kcirt eht deedni si rekram eht sa n\ ,ees s'teL .taht dessim I sseug I eht ot ,*enilwen sti htiw* ,ecaps dloh ytpme eht sdneppa dnammoc G ehT dna ,emit a ta eno ecalp otni sretcarahc edils uoy nehT .ecaps nrettap .enilwen artxe eht fo dir teg -- Mark Brader, msb@sq.com sed -e "s;??\\([-=(/)']\\);?\\\\?\\1;g" SoftQuad Inc., Toronto will fix them... -- Karl Heuer My text in this article is in the public domain.