Home > Archive > PERL Beginners > October 2006 > Hard or Easy? To find string, then grab criterion matched lines above and below?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Hard or Easy? To find string, then grab criterion matched lines above and below?
|
|
| samiam@mytrashmail.com 2006-10-05, 6:58 pm |
|
Hello All,
I know this is a trivial parse / grep job for any Perl rake worth his
salt, but does anyone have guidance on how this Perl newbie might pull
a string from one file and use this string to pull the lines in another
file out, and also pull the first line before (matching criteria) and
the first line after (matching criteria.)
I have described this in detail below.
At first I thought to use VBScript, but then I realized that Perl is
portable, doesn't necessarily have to be installed on the server, and
probably has MUCH better string processing power than VBScript. I also
considered grep, but still thought I could reuse the Perl solution in
more places.
Any input is GREATLY appreciated!
L,
S
------------
Summary: I need to find CSR numbers in FILE-A that map to registry key
entries in FILE-B, and report the pertinent surrounding info.
Detail:
I am looking to:
a.) find the lines in *.aud files with "Fail" in them
b.) Extract the Section number from the beginning of that same line.
I'll call this Section number a "CSR #"
Then use that CSR# to pull from a 2nd *.dsc file :
a.) Pull first line with CSR#
b.) Pull the first line above it with anything between two # signs,
which are section titles like this #Windows Messenger#
c.) Pull the SECOND registry key instance that is on any line below the
line with the CSR #
d.) Out put this data into a CSV file like this:
CSR#, Section Title, Registry Key
5.6.1.7.1, Windows Messenger Check, "HLM,
SOFTWARE\Policies\Microsoft\Messenger\Cl
ient,PreventRun,1,INTEGER"
Since there seem to be commas in the registry key entry, I suppose my
csv file would need to be delimited by another delimiter recognized by
Excel, which is where I ultimately want to display my data.
Below are two data samples like the data from which I will be culling.
The first sample is from a *.aud audit file.
The second is from the single DSC program file that either analyzes the
registry or can also write and change it.
Basically, I need to report the changes that our program will be making
to the registry. The audit files show the fail lines, which are lines
of a servers registry that needs to be brought into compliance.
server.aud file (audit file)
5.2.4~Local Printers Shared~NA~PASS~NA
5.8.1~FTP Server Installed~NA~PASS~NA
5.6.2~POSIX Subsystem Installed~PASS~PASS~
5.2.2~Posix Subsystem File Components - Posix.exe Not Found~NA~PASS~NA
5.2.2~Posix Subsystem File Components - Psxss.exe Not Found~NA~PASS~NA
5.2.2~Posix Subsystem File Components - Psxdll.dll Not Found~NA~PASS~NA
5.6.1.1~NetMeeting Disable Remote Desktop Sharing~FAIL~FAIL~
5.6.1.2~IE Security Zones are Local Only~FAIL~FAIL~
5.6.1.2.2~Allow User to Change IE Sec Policy~FAIL~FAIL~
5.6.1.2.3~IE Security Zones Map Editing~FAIL~FAIL~
5.6.1.2.4~IE Proxy Settings Set Per User~FAIL~FAIL~
5.6.1.2.5~IE Automatic Installs Disabled~FAIL~FAIL~
5.6.1.2.6~IE Software Update Check~FAIL~FAIL~
-----------------------------
analyze.dsc (script for analyzing/writing to registry)
# Windows Messenger #
dialog set,text1,"5.6.1.7.1 Windows Messenger Check"
dialog set,text2,"5.6.1.7.1 Do Not Allow Windows Messenger to be Run"
%%before =
@REGREAD(HLM,SOFTWARE\Policies\Microsoft
\Messenger\Client,PreventRun,)
REGISTRY
WRITE,HLM,SOFTWARE\Policies\Microsoft\Me
ssenger\Client,PreventRun,1,INTEGER
| |
| usenet@DavidFilmer.com 2006-10-05, 6:58 pm |
| sam...@mytrashmail.com wrote:
[snip multipost]
Please don't multipost. It's rude.
--
David Filmer (http://DavidFilmer.com)
| |
| samiam@mytrashmail.com 2006-10-05, 6:58 pm |
| Hi Dave, :-)
Sorry...didn't know. Aren't there some differing opinions on that?
Seems I've heard quite a few.
Some think that the people who love to jump in and call others rude are
more rude by far than those who might not have known better or if they
did certainly didn't mean any harm by commission or omission.
Some say that a better way to address non-malevolent behaviors might be
to use a bewildering array of other less rude categorizations such as:
"bad form"
"unconventional"
"disdained," etc, etc.
For some reason, the people who are quick to get red in the face and
bellow out, "How Rude!!!" at the slightest deviation from ~~their~~
sensibilities think they are somehow exempt from being rude by
ungraciously calling out the mistakes of others in a rude public way.
How ironic then that the accuser bringing a charge of rudeness is the
very exemplar of rudeness himself :)
Entertaining, if not wholly unhelpful :)
Even more interesting is that I see you are a very busy fellow and the
self ordained "Rude Policeman" :)
I googled DavidFilmer and "rude" and there are 151 occurances of you
either calling someone rude or being called rude yourself. I wonder if
they make a nicorette like gum for rudeness, perhaps...over time...you
could learn to cut back :-)
Love,
Sam :-)
usenet@DavidFilmer.com wrote:
> sam...@mytrashmail.com wrote:
>
> [snip multipost]
>
> Please don't multipost. It's rude.
>
> --
> David Filmer (http://DavidFilmer.com)
| |
| usenet@DavidFilmer.com 2006-10-05, 6:58 pm |
| samiam@mytrashmail.com wrote:
> Sorry...didn't know. Aren't there some differing opinions on that?
> Seems I've heard quite a few.
I have never heard anyone (ever) condone usenet multiposting
(crossposting is a different matter - I think it's often abused but I
rarely comment on it). I will always flag each and every multipost I
notice. Some folks may consider that rude in itself - I could care
less. Post according to long-established usenet conventions (and
within the guidelines of the group/list charter) and you will usually
get prompt and courteous help (maybe from me).
--
David Filmer (http://DavidFilmer.com)
| |
| samiam@mytrashmail.com 2006-10-05, 6:58 pm |
| Oh...I didn't realize my post showed up twice. I didn't mean for that
at all. I certainly get no benefit from posting twice in a row - it was
some kind of glitch and not something I do or would do.
I thought you were referring to the fact that I asked this question in
more than one place.
I'll see if I can remove the 2nd post.
L,
S
use...@DavidFilmer.com wrote:
> samiam@mytrashmail.com wrote:
>
> I have never heard anyone (ever) condone usenet multiposting
> (crossposting is a different matter - I think it's often abused but I
> rarely comment on it). I will always flag each and every multipost I
> notice. Some folks may consider that rude in itself - I could care
> less. Post according to long-established usenet conventions (and
> within the guidelines of the group/list charter) and you will usually
> get prompt and courteous help (maybe from me).
>
> --
> David Filmer (http://DavidFilmer.com)
|
|
|
|
|