Re: [9fans] removing spaces from filenames

2012-03-22 Thread Peter A. Cejchan
thank you very much , Eric!
I don't use strange chars in my filenames, but others do, sigh,

++pac



[9fans] removing spaces from filenames

2012-03-21 Thread Peter A. Cejchan
# 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



Re: [9fans] removing spaces from filenames

2012-03-21 Thread yy
2012/3/21 Peter A. Cejchan tyap...@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 .



Re: [9fans] removing spaces from filenames

2012-03-21 Thread erik quanstrom
 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