remove brackets from files name
remove brackets from files name
(OP)
Hi
I have files where the name contains brackets. I would like to remove the brackets from the names. I am using ksh.
The files before:-
abc1(1).ctl
abc2(1).ctl
abc3(1).ctl
abc4(1).ctl
I would like to change them to:-
abc1.ctl
abc2.ctl
abc3.ctl
abc4.ctl
Thank you
Kais
I have files where the name contains brackets. I would like to remove the brackets from the names. I am using ksh.
The files before:-
abc1(1).ctl
abc2(1).ctl
abc3(1).ctl
abc4(1).ctl
I would like to change them to:-
abc1.ctl
abc2.ctl
abc3.ctl
abc4.ctl
Thank you
Kais
RE: remove brackets from files name
You wrote "remove the brackets", but in your example you removed the parenthesis and everything between them. This code does the later :
CODE --> Ksh93
Feherke.
feherke.ga
RE: remove brackets from files name
Thank you for that but I had an error see below.
#for file in *(*)*; do echo mv "$file" "${file//\(*\)}"; done
sh: "${file//\(*\)}": The specified substitution is not valid for this command.
RE: remove brackets from files name
It works for me with Ksh93 and MirBSD Ksh. I assume you have Ksh88, but I not have that version.
This one works in Dash, so should work in any Bourne-compatible shell :
CODE --> Dash
But better see if you have rename ( sometimes rename.pl ) from the perl package ( the one from util-linux package replaces only fixed strings, but that one you probably not have anyway ) :
CODE
Feherke.
feherke.ga
RE: remove brackets from files name
Thank you again.
rename command is not available.
I had to amend the above because I have a file without the brackets too.
for file in *(*)*
do
nfile="`echo "$file" | sed 's/(.*)//'`"
if [[ $file != $nfile ]]; then
mv $file $nfile
fi
done
RE: remove brackets from files name
Oops. You are right, Kais. Either that, or fix my glob :
CODE
Feherke.
feherke.ga