Developer Developer - 1 year ago 78
Perl Question

Execute Perl Regular Expression on all zip files unix

I have collections of zip files in that i have some xml data.On that data i want to execute Perl regular expression from command line .But the command is only working on non zipped files and for zipped file it is not wokring.

perl -ne '/ID:([0-9.]+).+Test=\"([\d\w.-\s]+)\"/ and print "$1 $2\n"' data.log.gz | sort -nr | uniq -c | sort -nr

Sample XML structure:

ABC ID:12342132: <?xml version="1.0" encoding="UTF-8"?><a Test="ABC"></a>

Answer Source

Zipped files won't contain the data that you want in a format that you can easily parse with Perl. You need to unzip them first. But the Unix command zcat can you that on the fly for you.

$ zcat data.log.gz | perl ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download