in reply to Grep asterisk sign in input file
Hi all, i am currently thinking of improving a script, that this script will read through an input file and a waiver.csv. Input file is a timing violations report and waiver.csv is to state which ports/pins timing violations can be waived. Basically, i am able to write the script out. But now, in the waiver file, now the pins/ports name will have wildcard * which the user no need to key in so many data inside, with the strings before the wildcard * match will do. Input file example: (first column is scenario, second is pins/ports name, third is target threshold, fourth is the result threshold, the result threshold must be lower or equal to the target threshold)
f1 c4a_123 350.00 3251.94 -2901.94 (VIOLATED) f1 c4b_123 350.00 2419.08 -2069.08 (VIOLATED) f2 c4emib_2060 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2061 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2062 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2063 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2064 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2065 250.00 2000.00 -1750.00 (VIOLATED) and so on
Waiver.csv, first column is pins/ports name, second is the target threshold value, third is adjusted target threshold value
c4a_123,350.00,3300.00,"Justification","Waived,by","Waived,Date","Appr +oved,by","Approved,date" c4emib_*,250.00,2000.00,"Justification","Waived,by","Waived,Date","App +roved,by","Approved,date"
So the expected outcome result file is like this:
f1 c4a_123 350.00 3251.94 -2901.94 (WAIVED) f1 c4b_123 350.00 2419.08 -2069.08 (VIOLATED) f2 c4emib_2060 250.00 2000.00 -1750.00 (WAIVED) f2 c4emib_2061 250.00 2000.00 -1750.00 (WAIVED) f2 c4emib_2062 250.00 2000.00 -1750.00 (WAIVED) f2 c4emib_2063 250.00 2000.00 -1750.00 (WAIVED) f2 c4emib_2064 250.00 2000.00 -1750.00 (WAIVED) f2 c4emib_2065 250.00 2000.00 -1750.00 (WAIVED)
my previous code is able to filter it out the expected output. But now since the wildcard is inserted in waiver file so the user no need to key in so many data if the pins/ports name are similar in the characters in front, so i no have the idea of (1) How my script can read the * wildcard symbol (2) and apply in the hash, to check line by line in input file for te strings that matched My code is like this:
#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; use Data::Dumper; # Source script my $report = $ARGV[1] ; my $waiver = $ARGV[3] ; my $result = $ARGV[5] ; # Set up a hash to receive the information my %identifier = (); # Read the violations file into the hash open my $filter, '<', $waiver or die; while (my $vline = <$filter>) { next unless $vline =~ /\S/; #skip blank lines $vline =~ s/^\S+//; #trim leading space my ($pins2, $threshold2, $newthreshold2) = split /,/, $vline; $identifier{$pins2}{'threshold2'} = $threshold2; $identifier{$pins2}{'newthreshold2'} = $newthreshold2; } print Dumper \%identifier; # Read input file line by line and compare 2 files open my $input, '<', $report or die; open my $output, ">", $result or die; while (my $wline = <$input>){ my (undef,$scenario, $pins1, $threshold1, $newthreshold1, $diff, $ +status) = split /\s+/, $wline; # overwrite values if match if ($_ =~ $identifier{$pins1.}) { if ( ($threshold1 == $identifier{$pins1}{'threshold2'}) && ($newth +reshold1 <= $identifier{$pins1}{'newthreshold2'}) ) { $status = '(WAIVED)'; } } printf $output "%-44s %-24s %-8s %-8s %-8s %-10 +s\n", $scenario, $pins1, $threshold1, $newthreshold1, + $diff, $status; } close $filter; close $input; close $output;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Wildcard in a hash
by shmem (Chancellor) on Jul 27, 2017 at 06:49 UTC | |
|
Re: Wildcard in a hash
by tybalt89 (Monsignor) on Jul 27, 2017 at 15:09 UTC | |
|
Re: Wildcard in a hash
by poj (Abbot) on Jul 27, 2017 at 06:14 UTC | |
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 07:00 UTC | |
|
Re: Wildcard in a hash
by Anonymous Monk on Jul 27, 2017 at 02:56 UTC | |
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 03:21 UTC | |
by Anonymous Monk on Jul 27, 2017 at 03:51 UTC | |
by DespacitoPerl (Acolyte) on Jul 27, 2017 at 04:57 UTC | |
by AnomalousMonk (Archbishop) on Jul 27, 2017 at 06:38 UTC | |
by Anonymous Monk on Jul 27, 2017 at 09:47 UTC | |
|
Re: Wildcard in a hash
by Anonymous Monk on Jul 27, 2017 at 14:19 UTC | |
by choroba (Cardinal) on Jul 27, 2017 at 14:39 UTC | |
by DespacitoPerl (Acolyte) on Aug 15, 2017 at 08:10 UTC | |
by shmem (Chancellor) on Aug 15, 2017 at 09:19 UTC | |
by DespacitoPerl (Acolyte) on Aug 16, 2017 at 02:25 UTC | |
by shmem (Chancellor) on Aug 16, 2017 at 06:16 UTC | |
|