Best one-liner?

Hi @daniel.m.tripp ,
I tried rename script. It works fine for me.
Just for interest here is how we would have gone about it 40 years ago. The environment then was a minicomputer running Berkeley Unix ( BSD), an ascii terminal, just a CLI, not windows, no copy/paste, no apps, just a few unix utilities. The utilities are not up to it so we have to make one. So lets start with a small C program to turn one filename into a clean filename removing blanks and specials.
So here is nbs.c
/* nbs.c - remove blanks and special chars from a string */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

main (int argc, char *argv[])
{
int i,j,c;
char *s;
for(i = 1; i<argc; i++){
s = argv[i];
screen(s);
printf("%s",s);
}
}

void screen(char s[])
/* remove blanks and special chars from s */
{
int i,j;
for(i = j = 0; s[i] != ‘\0’; i++)
if(s[i] != ’ ’ && isalnum(s[i]))
s[j++] = s[i];
s[j] = ‘\0’;
}
It just leaves out all unwanted characters.
Compile it
gcc nbs.c -o nbs
and put it somewhere in your PATH eg
cp nbs ~/bin

So now we have a traditional unix utility
To use it over many files we need a script, the choice is sh or csh. With sh we do
#! /bin/sh
for i in * ; do
echo $i
echo nbs $i
mv “$i” “nbs $i
done
and lets call it nbs.sh, and make it executable.
I have a small test directory
nevj@mary:/common/Cwork/test$ ls
‘abc def’ asd#fgr ’ tes& < t blan^k’
so from in there we run
nevj@mary:/common/Cwork/test$ …/nbs.sh
tes& < t blan^k
testblank
abc def
abcdef
asd#fgr
asdfgr
nevj@mary:/common/Cwork/test$ ls
abcdef asdfgr testblank

So it works.
Not the best way today, but a brief view of where we came from.

Regards
Neville

1 Like