Register
It is currently Thu Jul 24, 2014 8:37 am

Using AWK within an AWK program problem...


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Wed Nov 15, 2006 4:15 am   

Joined: Wed Nov 15, 2006 1:21 am
Posts: 3
Location: Grand Blanc, MI
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{
}


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP