- $fileName = Get-ChildItem -Path "$filePath" -Recurse -Filter "fileName.txt"
- $resultMatch = Select-String -Path $fileName.FullName -Pattern "root"
-
- if([string]::IsNullOrWhiteSpace($resultMatch))
- {
- $content=''
- $content = "[
- {root,
- [
- {child, 123}
- ]}
- ]."
-
- Clear-Content $newfileName
- Add-Content $newfileName $content
- }
If root was found i need to check for child child
if not exists I need to append else add. I am doing as follows $resultMatch = Select-String -Path $fileName.FullName -Pattern "{child,"
I am thinking of a better way to do it, so any one having any idea.
The entire file will have as follows
- [
- {root,
- {child, 0}, if exists replace the entire line else add
- {child, 1}
- ]}
- ].