rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: how to drop the nth element of a list
@ 1991-10-18 19:48 Rich Salz
  0 siblings, 0 replies; 4+ messages in thread
From: Rich Salz @ 1991-10-18 19:48 UTC (permalink / raw)
  To: byron, rc

I don't have seq.  This seems to work okay:
	x=(a b c d e f)
	n=3
	{ for (i in $x ) echo $i } | sed -e $n^d
	a
	b
	d
	e


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to drop the nth element of a list
@ 1991-10-18 19:42 DaviD W. Sanderson
  0 siblings, 0 replies; 4+ messages in thread
From: DaviD W. Sanderson @ 1991-10-18 19:42 UTC (permalink / raw)
  To: rc

> Packaging this into an rc function is left as an excercise for the
> reader...

One (simple) solution is the 'chop' function I contributed to the
rc 1.2 EXAMPLES file.

DaviD Sanderson (dws@cs.wisc.edu)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: how to drop the nth element of a list
@ 1991-10-18 19:31 Byron Rakitzis
  0 siblings, 0 replies; 4+ messages in thread
From: Byron Rakitzis @ 1991-10-18 19:31 UTC (permalink / raw)
  To: rc

You can do this in at most the cost of 3 forks and 2 execs; suppose that
$foo contains the list you want to operate on, and $n contains the number
of the element you wish to remove:

	foo=$foo(`{seq 1 $#foo | grep -v '^'$n'$'})

You could also probably do the stuff in backquotes in a single awk job,
but it involves more messing around with quotes, and takes longer to
type. Still, it will run faster:

	awk 'BEGIN{
		for (i = 1; i < '$#foo'; i++)
			if (i != '$n')
				print i
		exit
	}'

Packaging this into an rc function is left as an excercise for the
reader...


^ permalink raw reply	[flat|nested] 4+ messages in thread

* how to drop the nth element of a list
@ 1991-10-18 16:38 malte
  0 siblings, 0 replies; 4+ messages in thread
From: malte @ 1991-10-18 16:38 UTC (permalink / raw)
  To: rc

Does anyone have a good idea to drop the nth element from a list?
I can only think of something using head(1) and tail(1), which is
not too efficient.


_______________________________________________________________________________
malte@techfak.uni-bielefeld.de

send mail reply to:	Universitaet Bielefeld, Technische Fakultaet
		z. Hd. Malte Uhl
		Postfach 8640
		4800 Bielefeld 1



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1991-10-18 19:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-10-18 19:48 how to drop the nth element of a list Rich Salz
  -- strict thread matches above, loose matches on Subject: below --
1991-10-18 19:42 DaviD W. Sanderson
1991-10-18 19:31 Byron Rakitzis
1991-10-18 16:38 malte

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).