From mboxrd@z Thu Jan 1 00:00:00 1970 To: 9fans@cse.psu.edu Date: Thu, 7 Feb 2008 09:55:08 +0000 From: "Douglas A. Gwyn" Message-ID: <47AA38CF.5AC2EDD9@null.net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit References: Subject: Re: [9fans] Non-parallel loop in Sam Topicbox-Message-UUID: 4aea02ba-ead3-11e9-9d60-3106f5b1d025 > My question is, how to > impliment non-parallel loop/condition commands in Sam? As you noticed, it's a different model from ed, sed, etc. In sam, you can specify sequential edits on separate lines, and a collection of lines can be grouped into a single action by surrounding the lines with braces { }. > In another > word, how to do things, such as inverse all lines, in Sam Don't forget that you have a lot of text-oriented tools at your disposal in any Unix or Plan 9 environment. To reverse the order of lines within a file already opened by sam, I would simply enter the following sam commands: ,| nl | sort -rn ,x/^ +[0-9]+ /d (on Solaris; maybe a slight change would be needed on Plan 9). This would be better packaged as a shell script, using sed rather than sam for the final number-stripping operation. You could then merely invoke that script for whatever "dot" region is selected in sam: | reverse # the script name It is nice to build up a little collection of useful editing scripts. Sometimes it is useful to enter nroff source and pipe it through nroff for automatic formatting: unformatted text .pl 12p\"prevent spacing to end of page afterward .ll 2i .tl 'le'ctr'ri' .ce centered title formatted text unformatted text Highlight (set dot to) all but the "unformatted text" and enter the same command | nroff -Tlp (on Solaris; for Plan 9 -Tlp is probably different). The -ms or other nroff macro package could be used, as desired.