User:Subashlamichhane77/sandbox

$Content = Get-Content "C:\Users\Suabsh\Desktop\New folder\subashl.txt" $Content | Foreach { if ($_ -ilike "*@name") {			Write-Output $_ } }

$Content = Get-Content "C:\Users\Suabsh\Desktop\New folder\subashl.txt" $Content | Foreach { if ($_ -ilike "*@name") {			$_ -replace "@name","subash" #Write-Output $_ } }

$Content = Get-Content "C:\Users\Suabsh\Desktop\New folder\subashl.txt" $Content = $Content | Foreach-object { $_ -replace "@name","subash" } $Content | set-content "C:\Users\Suabsh\Desktop\New folder\mop.txt"

Get-Content "C:\Users\Suabsh\Desktop\New folder\subashl.txt" | Foreach-object { $_ -replace "@name","subash" } | set-content "C:\Users\Suabsh\Desktop\New folder\mop.txt"


 * 1) read from excel and replace in textfile

$xlsx = New-Object -ComObject Excel.Application $wb = $xlsx.Workbooks.open("C:\Users\Suabsh\Desktop\New folder\sub.xlsx") $sheet = $wb.WorkSheets.Item(1) $userdrange = $sheet.UsedRange $name = $userdrange.Cells.Item(1,1).value2 $company = $userdrange.Cells.Item(2,1).value2 $wb.Close

$Content = Get-Content "C:\Users\Suabsh\Desktop\New folder\subashl.txt" $Content = $Content | Foreach-object { $_ -replace "@name",$name } $Content = $Content | Foreach-object { $_ -replace "@comp",$company } $Content | set-content "C:\Users\Suabsh\Desktop\New folder\mop.txt"


 * 1) with for loop

$xlsx = New-Object -ComObject Excel.Application $wb = $xlsx.Workbooks.open("C:\Users\Suabsh\Desktop\New folder\sub.xlsx") $sheet = $wb.WorkSheets.Item(1) $userdrange = $sheet.UsedRange $Content = Get-Content "C:\Users\Suabsh\Desktop\New folder\subashl.txt" for ($i=1; $i -le $userdrange.Rows.Count; $i++) {   $name = $userdrange.Cells.Item($i,1).value2 $aname = $userdrange.Cells.Item($i,2).value2 $Content = $Content | Foreach-object { $_ -replace $name,$aname } } $wb.Close $Content | set-content "C:\Users\Suabsh\Desktop\New folder\mop.txt"

$Content = Get-Content "C:\Users\Suabsh\Desktop\New folder\Old config.txt" $Content | Foreach { #if ($_ -ilike "*address*.*.*.*/*") if ($_ -match "^\s?[a-z]{7}\s[0-9]{1,3}.{1}[0-9]{1,3}.{1}[0-9]{1,3}.{1}[0-9]{1,3}.{1}/{1}[0-9]{1,2}$") {           $line = $_ $ip = $line.Substring(9,9) Write-Output $ip } }