Help with Using PowerShell to split a file by a particular string and saving as specific name
Good afternoon, I hope someone can assist.
I need assistance being able to split a file into multiple files with a specific name.
So I use get-content to read the file
16/07/2024 MessageA – 1
***Line 1
***Line 2
*End of Message
16/07/2024 MessageB – 2
***Line 1
***Line 2
*End of Message
16/07/2024 MessageC – 3
***Line 1
***Line 2
*End of Message
As you can see there are three messages in the object when i use get-content. I wish to split this file into (which in this case would be three messages) once the string *End of Message* is seen. Also giving the name of each file to be the first line in each of the files.
filename – MessageA.txt
16/07/2024 MessageA – 1
***Line 1
***Line 2
*End of Message
filename – MessageB.txt
16/07/2024 MessageB – 2
***Line 1
***Line 2
*End of Message
Good afternoon, I hope someone can assist. I need assistance being able to split a file into multiple files with a specific name. So I use get-content to read the file16/07/2024 MessageA – 1***Line 1***Line 2*End of Message 16/07/2024 MessageB – 2***Line 1***Line 2*End of Message 16/07/2024 MessageC – 3***Line 1***Line 2*End of Message As you can see there are three messages in the object when i use get-content. I wish to split this file into (which in this case would be three messages) once the string *End of Message* is seen. Also giving the name of each file to be the first line in each of the files.filename – MessageA.txt16/07/2024 MessageA – 1***Line 1***Line 2*End of Message filename – MessageB.txt16/07/2024 MessageB – 2***Line 1***Line 2*End of Message Read More