01-09-06 11:02 PM
bmdavll@gmail.com wrote:
> That works great for a single file, but how do I do it for all files
> matching a pattern. Do I need a for loop? And what does "##*--" do
> exactly to the name variable to remove the leading dashes?
>
> Thanks,
> David
>
Please read http://cfaj.freeshell.org/google before posting again as
you're falling prey to google.
Wrt your questions. If you're responding to this posting of mine:
> If there's no more than one consecutive "-" in your file names, and always
2 or more in the preceeding text:
>
> read name < file && mv file "${name##*--}.txt"
then, yes, you need to put it in a loop for multiple files, e.g.
for file in *
do
read name < "$file" && mv "$file" "${name##*--}.txt"
done
and the "##*--" removes every character in $name up to and including the
last 2 consectutive dashes. Look for "parameter substitution" in your
shells man page.
Ed.
[ Post a follow-up to this message ]
|