0

I have below in a text file :

development_XYZ_backup_2019_02_07_030515_9125395.bak,
development_PQRS_backup_2019_02_07_030516_0315514.bak

I need to delete:

,development_PQRS_backup_2019_02_07_030516_0315514.bak

So the text file will contain only:

development_XYZ_backup_2019_02_07_030515_9125395.bak

I'm not sure where to start, any help is appreciated.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
script0207
  • 345
  • 1
  • 4
  • 12
  • See: how to process files [line by line](https://stackoverflow.com/a/33511982/503046). – vonPryz Feb 08 '19 at 08:37
  • This is a bit more complicated since it's not only a line to delete. You will have to check each line if it ends with a comma. Further you need to delay the output of each line until you know if the next line is to be deleted. In that case you should remove the last char if it is a comma. Hope that helps a bit to extend the "line by line" processing to fulfill your needs. – harper Feb 08 '19 at 08:46
  • Possible duplicate of [Powershell Replace Multiline](https://stackoverflow.com/questions/41451044/powershell-replace-multiline) – henrycarteruk Feb 08 '19 at 11:23
  • `(Get-Content .\file.txt -raw) -replace '(,\r?\n)?development_PQRS_backup_2019_02_07_030516_0315514.bak'` –  Feb 08 '19 at 11:39

0 Answers0