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

Welcome Forums General PowerShell Q&A After select position in a file , find the ligne with a string of my choice.

Viewing 6 reply threads
  • Author
    Posts
    • #236563
      Participant
      Topics: 9
      Replies: 54
      Points: 135
      Rank: Participant

      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.

      • This topic was modified 3 weeks, 6 days ago by Renaud.
    • #236575
      Participant
      Topics: 3
      Replies: 431
      Points: 1,533
      Helping Hand
      Rank: Community Hero

      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
      
    • #236623
      Participant
      Topics: 9
      Replies: 54
      Points: 135
      Rank: Participant

      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.

    • #236629
      Participant
      Topics: 9
      Replies: 54
      Points: 135
      Rank: Participant

      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 😉

    • #236632
      Participant
      Topics: 3
      Replies: 431
      Points: 1,533
      Helping Hand
      Rank: Community Hero

      Can you show examples of the output you desire?

    • #236635
      Participant
      Topics: 9
      Replies: 54
      Points: 135
      Rank: Participant

      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”

      • This reply was modified 3 weeks, 6 days ago by Renaud.
      • This reply was modified 3 weeks, 6 days ago by Renaud.
      • This reply was modified 3 weeks, 6 days ago by Renaud.
    • #238391
      Participant
      Topics: 9
      Replies: 54
      Points: 135
      Rank: Participant

      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 😉

Viewing 6 reply threads
  • You must be logged in to reply to this topic.