I'm working on a script that renames JAR files based on their real name contained within the file itself. The easiest way I can think to do this is with the code I have written below. Of course it requires some outside files, but I'll work on that later. The problem lies within how awk is separating each record in the MANIFEST.MF file into fields. Instead of the default " " FS, I need to change it to ": ", but when I do I get a syntax error when I try to run the script. (BEGIN { FS = ": " } is the part that trips it up) I can't figure out how to make this work any differently without getting into some huge and confusing for loops outside of this program.
Code:
#
#rename.awk
#Author: Michael Beutler
#
BEGIN{
}
#
# main logic is here
#
{
sfile = $1 #save name of current file for later use
excmd = "jar xf " $1 " META-INF/MANIFEST.MF" #extract file with name of program
cpcmd = "cp " $1 " `awk 'BEGIN { FS = ": " } /MIDlet-Name:/ {print substr($2,1,length($2)-1)}' ./META-INF/MANIFEST.MF`.jar" #rename file from MANIFEST.MF data
# rmcmd = "rm ./META-INF/MANIFEST.MF" #decided to skip since file is overwritten automatically
printf "Renaming %s\n",sfile #display the current file being renamed
system(excmd)
system(cpcmd)
}
#
# End action, if any, e.g. clean ups
#
END{
}