I'm trying to put together a shell script that will append specific prefixes based on the content of filenames. I think I have this part down. However, I want to append before that part a process that will remove the current prefix before it renames the files with the new prefix.
For example, if all the files I want to rename, for example are:
---
ALPHANUM.ABCDEFG
ALPHANUM.HIJKLMNOP
ALPHANUM.QRSTUV
ALPHANUM.WXYZ
ALPHANUM.01234567890
---
and depending on the contents, if $[0-9] append the prefix "NUM." and $[A-Z] append prefix "ALPHA". The part where I'm stuck at is trying to figure out how to remove the "ALPHANUM." prefix before I do any appending.
Tried searching through the forums with "remove suffix, change suffix, remove prefix, change prefix," and "prefix" to get some examples, but did not spot anything I'm trying to do.
Please help.
Thanks!
With ksh:
$ filename=ALPHANUM.abc
$ echo ${filename#ALPHANUM\.}
abc
$
Thank you. I would like to use the bash shell though. Is there a website containing the differences between the shells, and specify which variable / command relates to the other, etc.? Also, the files I am actually working with to rename contains both alpha and numeric characters. How do I specify that the one common perfix for all the files are removed? (Using the bash shell.) Thanks!
Hi Lee,
I tried this snipped to identify if the file name extension has numeric character. let me know if this snippet ring any bells.
echo "${an}"| nawk '{
if ( $0 ~ /[0-9]/ )
{
printf("%s is num\n", $0);
}
else
printf("%s is alpha\n", $0);
}
'
Hi. Thanks for your help. I should've mentioned that the string of text after the ALPHANUM phrase are not extensions. They have their own extensions actually, like .txt. Sorry for not specifying this before.
well, they may not be extensions but they are ., right? so as long as they are . the above should still work
Is there a command that will only remove the specified prefix?? That's the only place I'm stuck at.
The examples provided were just examples to help paint the picture of what I was trying to do. Sorry for being unclear.
As for the appending the appropriate prefix, etc., that part's already been typed out. I just want to include a part in the beginning of the shell script that will remove the prefix before it does the modifying the filenames any further.