Skip to content

Instantly share code, notes, and snippets.

@earnhardt3rd
Created June 19, 2023 13:56
Show Gist options
  • Select an option

  • Save earnhardt3rd/babc528958b8dd65288f67b463be3f33 to your computer and use it in GitHub Desktop.

Select an option

Save earnhardt3rd/babc528958b8dd65288f67b463be3f33 to your computer and use it in GitHub Desktop.
require 'getopts.pl';
Getopts('m:d:t');
my $MODE = uc($opt_m) || "";
my $DEBUG = $opt_d || 0;
if (defined $opt_t) { my %TEST = &findStrInFile();}
1;
sub findStrInFile {
my $sFile = shift || "";
my $sCom = shift || "";
my $sStr = shift || "";
my $gawk = shift || "";
my $rtn = "";
print "--findStrInFile\n {\n" if $DEBUG >0;
if ($sStr eq "") {
print " Nothing to Search for???\n";
return "ERROR! Nothing to Search For???";
}
if (! -f $sFile) {
print " Could not locate search file: $sFile\n";
return "ERROR! Could not locate file:$sFile";
}
print " Looking for:'$sStr' in '$sFile'\n" if $DEBUG >0;
my $cmd = "findstr /C:\"${sStr}\" \"${sFile}\"";
if ($sCom ne "") {$cmd .= "|findstr /V /C:^${sCom}";}
if ($gawk ne "") {$cmd .= "|gawk \"{${gawk}}\"";}
print " --$cmd\n" if $DEBUG >0;
my $cmdX = `$cmd 2>&1`;
chomp($cmdX);
print " --$cmdX\n" if $DEBUG >0;
if ($cmdX eq "") {
$rtn="NOT_FOUND";
} else {
$rtn = $cmdX;
$rtn =~ s/.*${sStr}//;
$rtn =~ s/"//g;
if ($rtn =~ /^PDM/) {$rtn =~ s/^PDM/${PDM}/;}
if ($rtn =~ /^NXROOT/) {$rtn =~ s/^NXROOT/${NXROOT}/;}
}
print " RTN:$rtn\n" if $DEBUG >0;
print " }\n" if $DEBUG >0;
return $rtn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment