Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

break big file into multiple files

$
0
0

I have a directory with several log files with content similar to the one below. I need to create a PS script that can extract contents from [BEGIN] to [END] section of the log file and put them into a new file and name the file with its sequence number and delete the source log then after. Thank you in advance for any help.

For eg:

I would like to split the following log into 3 different files and name them with their sequence number:

[BEGIN],Fri,Jun,28,18:34:03,2013:REGISTRY START, SEQ0011;

[0],Fri,Jun,28,18:34:03,2013:CREATE Folder$ in C$;

[1],Fri,Jun,28,18:34:03,2013:COPY LOG$ in  C$\Folder$;

[2],Fri,Jun,28,18:34:03,2013:COPY File in  C$\Folder$;

[END] Fri Jun 28 18:34:03 2013: REGISTRY STOP, SEQ0011;

[BEGIN],Fri,Jun,28,18:34:03,2013:REGISTRY START, SEQ12411;

[0],Fri,Jun,28,18:34:03,2013:CREATE Folder$ in C$;

[1],Fri,Jun,28,18:34:03,2013:COPY LOG$ in  C$\Folder$;

[2],Fri,Jun,28,18:34:03,2013:COPY File in  C$\Folder$;

[END] Fri Jun 28 18:34:03 2013: REGISTRY STOP, SEQ12411;

[BEGIN],Fri,Jun,28,18:34:03,2013:REGISTRY START, SEQ0121;

[0],Fri,Jun,28,18:34:03,2013:CREATE Folder$ in C$;

[1],Fri,Jun,28,18:34:03,2013:COPY LOG$ in  C$\Folder$;

[2],Fri,Jun,28,18:34:03,2013:COPY File in  C$\Folder$;

[END] Fri Jun 28 18:34:03 2013: REGISTRY STOP, SEQ0121;

 

Output:

Content of first file, SEQ0011.txt:

[BEGIN],Fri,Jun,28,18:34:03,2013:REGISTRY START, SEQ0011;

[0],Fri,Jun,28,18:34:03,2013:CREATE Folder$ in C$;

[1],Fri,Jun,28,18:34:03,2013:COPY LOG$ in  C$\Folder$;

[2],Fri,Jun,28,18:34:03,2013:COPY File in  C$\Folder$;

[END] Fri Jun 28 18:34:03 2013: REGISTRY STOP, SEQ0011;

Content of second file, SEQ12411.txt:

[BEGIN],Fri,Jun,28,18:34:03,2013:REGISTRY START, SEQ12411;

[0],Fri,Jun,28,18:34:03,2013:CREATE Folder$ in C$;

[1],Fri,Jun,28,18:34:03,2013:COPY LOG$ in  C$\Folder$;

[2],Fri,Jun,28,18:34:03,2013:COPY File in  C$\Folder$;

[END] Fri Jun 28 18:34:03 2013: REGISTRY STOP, SEQ12411;

Content of third file, SEQ0121.txt:

[BEGIN],Fri,Jun,28,18:34:03,2013:REGISTRY START, SEQ0121;

[0],Fri,Jun,28,18:34:03,2013:CREATE Folder$ in C$;

[1],Fri,Jun,28,18:34:03,2013:COPY LOG$ in  C$\Folder$;

[2],Fri,Jun,28,18:34:03,2013:COPY File in  C$\Folder$;

[END] Fri Jun 28 18:34:03 2013: REGISTRY STOP, SEQ0121;


Viewing all articles
Browse latest Browse all 6937

Trending Articles