Hello Everyone,
I need to create a script which can scan through a config file, then extract some specific info and write them into new files.
I am still a beginner, so it may appear to be an easy thing to most. I appreciate any kind of help you can offer on this.
Below are few lines from the input file:
BEGIN INITIALIZATION REGION=HALOC010
START REGION=HALOC010
BEGIN EXECUTE LCAQPRO1
BEGIN EXECUTE LCAQPRO2 GROUP=OACI410G
BEGIN EXECUTE PROGRAM=ICP9120 GROUP=KEE202
BEGIN EXECUTE PROGRAM=ICP9121 GROUP=KEE202
I need to list out the programs and scripts from the config file and create two new files. (Scripts are followed by the word 'EXECUTE ’ and programs are the ones followed by ‘PROGRAM=’)
File#1 should look like
LCAQPRO1
LCAQPRO2
File#2 should look like
ICP9120
Here is how I am trying to do, but it’s definitely not the right way. And the config file can have any number spaces between each word.
cat conf.file | where { $_ -match "EXECUTE"} > temp1.file
cat temp1.file | where { $_ -match "PROGRAM"} > temp2.file
type temp1.file | findstr /V /C:"PROGRAM" > temp3.file
Get-Content temp3.file | ForEach-Object {
$_.Split("EXECUTE", [System.StringSplitOptions]::RemoveEmptyEntries)
} | Set-Content temp4.file
Thanks.
Rakesh