After select position in a file , find the ligne with a string of my choice.

Hi all,

I’m really stuck…and i think it’s easy to do…

I have a file like this :

SCHED Full 0 1 604800 1 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 0
SCHEDWIN 0 0 0 0 0 0 0 0 61200 135000 0 0 0 0
SCHEDRES *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDPOOL *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDRL 1 1 1 1 1 1 1 1 1 1
SCHEDFOE 0 0 0 0 0 0 0 0 0 0
SCHEDSG *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*

SCHED Incr 1 1 604800 1 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 0
SCHEDWIN 0 0 0 0 0 0 0 0 0 0 0 0 0 0
SCHEDRES *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDPOOL *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
SCHEDRL 1 1 1 1 1 1 1 1 1 1
SCHEDFOE 0 0 0 0 0 0 0 0 0 0
SCHEDSG *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*

It's the configuration of a schedule of a NetBackup strategy.
We have the config of the Full schedule and the incremental schedule.

i could have to select the Full or the Incr.
The line of the configuration of Backup start time is "SCHEDWIN", i need to select this line

I try something like that :

$Label = "Full"
$ConfigBck = Get-Content "$PathConfig\$File"
ForEach($line in $ConfigBck){
    If($line -like "*$Label*"){
        Write-Host "IF: $line"
        While($Line -notlike "*SCHEDWIN*"){
            If ($foreach.moveNext()){
                Write-Host "Config $PolicyName : $($foreach.current)" 
                $Config =  $($foreach.current)
                Write-Host "PolicyName: $PolicyName"
            }
        }
    }
}

Not working at all
and this :

$SplitConf = Get-Content "$PathConfig\$File" | Select-String -Pattern "$Label" -context 0,2
ForEach($ligne in $SplitConf){
    If($ligne -like "*SCHEDWIN*"){
        Write-Host "$Ligne"    
    }
}

But in the $SplitConf, there is just one line.

So if the backup select is a full backup, how can i select the ligne SCHEDWIN ?
Thx for help.

Would this fulfill your need?

$SplitConf = Select-String -Path "$PathConfig\$File" -Pattern 'schedwin'|Foreach-object line

or

Select-String -Path "$PathConfig\$File" -Pattern 'schedwin'|ForEach-Object {$_.line}

Output:

SCHEDWIN 0 0 0 0 0 0 0 0 61200 135000 0 0 0 0
SCHEDWIN 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Hello Doug ^^

That’s depend, sometimes i need the Full configuration, and sometimes the Incr Configuration.
So the first variable is the type Full or Incr, after i need the SCHEDWIN below.

For explain this:
I have done a script to modify schedule of Netbackup strategie, so the schedule incremental or Full.
After i have modify it i want to rollback to the origin configuration, that i backup before any change on it.
So when i select the rollBack the two things to know is the name of the policy and the type of schedule, Full or Incr :wink:

Can you show examples of the output you desire?

When i have done a modify of a full Backup, to roll back i need the line :

First Select the line with schdeul type : SCHED Full 0 1 604800 1 0 0 0 *NULL* 0 0 0 0 0 0 -1 0 0
To have this line : SCHEDWIN 0 0 0 0 0 0 0 0 61200 135000 0 0 0 0

You must know the SCHEDWIN line could be at the 1 or 2 position after the line with the type of schedule, here “Full”

Just for information, i have used the foreach variable :

Example:

$Content = Get-Content "f:\doc.txt"
ForEach($line in $Content){
  If($line -like "*Full*"){
    Do{$null = $Foreach.MoveNext()}Until($foreach.Current -like "*SCHEDWIN*")
  }
}

Thx any way :wink: