* [9fans] removing spaces from filenames
@ 2012-03-21 9:26 Peter A. Cejchan
2012-03-21 13:20 ` yy
[not found] ` <CADErNDsJhiaoDRdfvmyZLtTwrsXVqK1V1CQzC5SwPGdS+HbsYg@mail.gmail.c>
0 siblings, 2 replies; 4+ messages in thread
From: Peter A. Cejchan @ 2012-03-21 9:26 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
# remove spaces from file names /// does not work
EXT=boo
rm run
for (old in `{9 ls *.$EXT}) {
new=`{echo $old | tr -d ' ' }
echo mv $old $new >> run
}
# this works, but is ugly:
# remove unwanted chars from file names
EXT=boo
9 ls *.$EXT > foo
9 cat foo | 9 tr -c [0-9][a-z][A-Z]'.''\x0a' '_' | 9 tr -s '_' '_' |
9 sed 's/_\././g' > foo2
paste foo foo2 > foo3
9 awk '{print "mv ", $0}' foo3 > run
what am I missing?
Thanks,
++pac
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9fans] removing spaces from filenames
2012-03-21 9:26 [9fans] removing spaces from filenames Peter A. Cejchan
@ 2012-03-21 13:20 ` yy
[not found] ` <CADErNDsJhiaoDRdfvmyZLtTwrsXVqK1V1CQzC5SwPGdS+HbsYg@mail.gmail.c>
1 sibling, 0 replies; 4+ messages in thread
From: yy @ 2012-03-21 13:20 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
2012/3/21 Peter A. Cejchan <tyapca7@gmail.com>:
> for (old in `{9 ls *.$EXT}) {
Here you are iterating over the elements of `{9 ls *.$EXT}, sepparated
by $ifs. Therefore, spaces are breaking your lines into word fields.
This is not what you want.
Your second example directly process whole lines (uses sed), so it
works. I think you will get what you want if you replace this line
with:
ifs='
' for (old in `{9 ls *.$EXT}) {
--
- yiyus || JGL .
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9fans] removing spaces from filenames
[not found] ` <CADErNDsJhiaoDRdfvmyZLtTwrsXVqK1V1CQzC5SwPGdS+HbsYg@mail.gmail.c>
@ 2012-03-21 16:36 ` erik quanstrom
2012-03-22 7:05 ` Peter A. Cejchan
0 siblings, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2012-03-21 16:36 UTC (permalink / raw)
To: 9fans
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [9fans] removing spaces from filenames
2012-03-21 16:36 ` erik quanstrom
@ 2012-03-22 7:05 ` Peter A. Cejchan
0 siblings, 0 replies; 4+ messages in thread
From: Peter A. Cejchan @ 2012-03-22 7:05 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
thank you very much , Eric!
I don't use strange chars in my filenames, but others do, sigh,
++pac
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-03-22 7:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-21 9:26 [9fans] removing spaces from filenames Peter A. Cejchan
2012-03-21 13:20 ` yy
[not found] ` <CADErNDsJhiaoDRdfvmyZLtTwrsXVqK1V1CQzC5SwPGdS+HbsYg@mail.gmail.c>
2012-03-21 16:36 ` erik quanstrom
2012-03-22 7:05 ` Peter A. Cejchan
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).