Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 409
  • Last Modified:

Unix or AWK, or applescript, script needed ASAP

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.
0
johnharbour
Asked:
johnharbour
  • 2
1 Solution
 
gkastenCommented:
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 ..
done

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'
0
 
johnharbourAuthor Commented:
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.
0
 
gkastenCommented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now