9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] removing spaces from filenames
Date: Wed, 21 Mar 2012 12:36:08 -0400	[thread overview]
Message-ID: <c5b7fba7d7787ed48d10fb2f72cc9cde@brasstown.quanstro.net> (raw)
In-Reply-To: <CADErNDsJhiaoDRdfvmyZLtTwrsXVqK1V1CQzC5SwPGdS+HbsYg@mail.gmail.c>

> ifs='
> ' for (old in `{9 ls *.$EXT}) {

i think ls and the temporary file are getting in the 
way.  if you use globbing and execing directly from
the shell you can avoid quoting problems.  for example,

	for(old in *^' '^*.$EXT)
		ifs=$nl mv $old `{echo $old | sed 's/ //g'}

and now for a digression ....

this looks like c programming to me.  unfortunately
mv doesn't take pairs, so we can't get rid of the for
loop, but we can generate parallel lists.

i'm going to assume that ☺ isn't in any of your file names.
you could pick something else.

the trick here is to paste ☺ onto the end of every list
element.  that way we know that '☺ ' are end-of-token
markers, and other spaces are just spaces.  then we
can delete the spaces without ☺s, then delete the ☺s
and then turn the remaining spaces (they mark the
end of a token) into newlines.

i'm going to assume that $ext also contains the '.'.

	old = *^' '^*$ext
	ifs=$nl new = `{echo $old^☺ | sed 's/([^☺]) /\1/g
		s/☺//g
		s/ /\n/g' }

(the last two sed steps are combinable; s/☺ /\n/g.)

now that we have this, we can

	while(! ~ $#new 0){
		mv $old(1) $new(1)
		old=$old(2-)
		new=$new(2-)
	}

this reminds me, the whole ifs thing is awkward because
it applies for the whole command which is almost never
what you want.  i modified rc to allow one to specify a
backquote splitter.  e.g.

	new = `$nl {echo $old^☺ | sed 's/([^☺]) /\1/g
		s/☺//g
		s/ /\n/g' }

- erik



  parent reply	other threads:[~2012-03-21 16:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-21  9:26 Peter A. Cejchan
2012-03-21 13:20 ` yy
     [not found] ` <CADErNDsJhiaoDRdfvmyZLtTwrsXVqK1V1CQzC5SwPGdS+HbsYg@mail.gmail.c>
2012-03-21 16:36   ` erik quanstrom [this message]
2012-03-22  7:05     ` Peter A. Cejchan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c5b7fba7d7787ed48d10fb2f72cc9cde@brasstown.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).