Skip to Main Content

Non-Target names still making through after filtering using awk

Tater_SaladApr 13 2018 — edited Apr 13 2018


  We're using:

Linux version 2.6.32-696.20.1.el6.x86_64 (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Fri Jan 12 15:07:59 EST 2018 x86_64 x86_64 x86_64 GNU/Linux

I wrote a script where I'm reading a group of files from a zip file using the following commands.

  for zip_file in $zip_files


            export file_names_unzip=`unzip -l $zip_file| awk '{IGNORECASE=1}/'processed_events.hist.'/{print $4}'`

            unzip -l $zip_file $file_names_unzip -d ..



This should return only lines that contain the prefixed string 'processed_events.hist.' However,  in my results file, I'm seeing the following values making it through the 'filter'.

  Length Date    Time    Name

---------  ---------- -----   ----

    23396 04-06-2018 15:00   boot.log

   304676 04-06-2018 15:00   ccfmsg.hist

     1725 04-06-2018 15:00   estar.log

    15368 04-06-2018 15:00   gERRORS.log

   409718 04-06-2018 15:00 processed_ccfmsg.hist

  4249429 04-06-2018 15:00   sys.log

---------                     -------

  5004312                     6 files

So the unzip -l shows the above files in its output along with the files prefixed by 'processed_events.hist.'

So I tried to 'filter' out those files in the awk command:

export file_names_unzip=`unzip -l $zip_file| awk '{IGNORECASE=1}/'processed_events.hist.'/&&!/boot.log/&&!/ccfmsg.hist/&&!/estar.log/&&!/gERRORS.log/&&!/processed_ccfmsg.hist/&&!/sys.log/{print $4}'`  

That didn't work.

The first filter line should have worked as well as the above filter. I'm curious as to what I can do here. I've tried a few other things I'll show below that also didn't work.

unzip -l $zip_file| awk '{IGNORECASE=1}/'processed_events.hist.'/{print $4}' > zip_names_striped.dat

file_names_unzip=`cat zip_names_striped.dat| awk '{IGNORECASE=1}!/'boot.log'/&&!/'ccfmsg.hist'/&&!/'estar.log'/&&!/'gERRORS.log'/&&!/'processed_ccfmsg.hist'/&&!/'sys.log'/{print $0}'`

The ONLY thing that works is taking the resultant output file this script generates called zip.out and again applying an awk filter to it shown below.

awk '{IGNORECASE=1}!/boot.log/{print $1}' zip.out | grep  boot.log | more

Just testing on the string 'boot.log' the command returns no output as should be expected. But this is 'after the fact' when the script finishes with 'boot.log' and the other unwanted strings still in it.

When I add that line to the script. that doesn't work either.

Post Details
Added on Apr 13 2018
1 comment