Unix or AWK, or applescript, script needed ASAP

Posted on 2010-01-07
Last Modified: 2013-12-26
need a script that does a loop and takes a filename from a line in a text file, copies the file to another directory, unzips the file, searches for a string *searchstring value*.ttf, deletes ttf file, and then rezips the file with the original name in the new directory.

Would prefer unix to run in terminal, but could be an applescript or automator workflow.
Question by:johnharbour
    LVL 1

    Accepted Solution

    If I understand your intent, this is what you're seeking:

    for i in `cat FILENAME`; do
      cp $i NEW_DIR/$i
      cd NEW_DIR
      gunzip $i
      unzippedfilename = `echo $i | sed 's/\.gz//g' `
      filetodelete = `egrep 'searchstring value\.ttf' $unzippedfilename`
      rm -f $filetodelete
      gzip $j
      cd ..

    The "filetodelete = ..." line searches the unzipped file for a line containing the name of the ttf file.
    If the ttf file is embedded in a line of text that has other text on it, then you might need to augment that line with some sed to strip out the extraneous text. For example, if your TTF file has no spaces in its filename, you could probably do something like this to strip out everything after and before the filename:
     | sed 's/\.ttf.*/.ttf/g' | sed 's/.* //g'

    Author Comment

    Thanks, I'll give it a try.  Unfortunately the filenames that we are trying to delete do have spaces and are not consistent except for that they contain the search value.
    LVL 1

    Expert Comment

    Is the search string constant, or is it also being pulled from the text file that contains the list of filenames?
    If the search string is the same for all searches, then you could hard-code it as:
     | sed 's/SEARCHSTRING\.ttf.*/.ttf/g' | sed 's/.* //g'

    If it is pulled on a per-file basis, I might be able to help if you can provide some additional context.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now