I have one txt file with the following information:
...Page 1
Student 1 data
FF-form feed character (may or may not appear) [INCLUDE in parsed file]
...Page 2
Student 1 data
Student 1 data
********** END OF TRANSCRIPT **********
FF-form feed character (definitely appears in this position) [do not include in parsed file]
...Page 1
Student 2 data
Student 2 data
FF-form feed character (may or may not appear) [INCLUDE in parsed file]
...Page 2
Student 2 data
********** END OF TRANSCRIPT **********<
FF-form feed character (definitely appears in this position) [do not include in parsed file]
...Page 1
Student 3 data
Student 3 data
Student 3 data
FF-form feed character (may or may not appear) [INCLUDE in parsed file]
********** END OF TRANSCRIPT **********
FF-form feed character (definitely appears in this position) [do not include in parsed file]
I’m trying to parse out the data so I can get three separate files and delete the form feed that only appear after the “end of transcript” line.
I end up with three files:
DATE_EDI_TRANSCRIPT_1.txt that contains “Student 1 Data”
DATE_EDI_TRANSCRIPT_2.txt that contains “Student 2 Data”
DATE_EDI_TRANSCRIPT_3.txt that contains “Student 3 Data”
However, the form feed in the extracted files is at the beginning of each file. I want to remove it from the beginning and the end of the file.
I get this:
I want to get this:
My code is:
```
$data = Get-Content "C:\EDICleanUp\1_ToBeProcessed\edi.txt" #Reading file
$Transcript = "_EDI_TRANSCRIPT_"
$Tdate = get-date -Format yyyy-MM-dd
$ProcessedFilePath = "C:\EDICleanUp\2_Processed"
$Complete = "C:\EDICleanUp\3_Original"
$ToBeProcessed = "C:\EDICleanUp\1_ToBeProcessed\edi.txt"
$fileIndex = 1; #To create file name
for ($itr = 0; $itr -le $data. Length; $itr++){
if($data[$itr] -eq "********** END OF TRANSCRIPT **********"){
$fileIndex+=1;
continue;
}
if((Test-Path "$ProcessedFilePath\$Tdate$Transcript$fileIndex.txt") -eq $false){
New-Item "$ProcessedFilePath\$Tdate$Transcript$fileIndex.txt" -ItemType "File"
}
#Append text to the file
Add-Content "$ProcessedFilePath\$Tdate$Transcript$fileIndex.txt" $data[$itr]
}
##Move original file to completed directory
Move-item $ToBeProcessed $Complete
```
I "think" the issue is with :
if($data[$itr] -eq "********** END OF TRANSCRIPT **********"){
$fileIndex+=1;
I can't figure out the proper code to look for the hard return/form feed.
I tried variations of:
'**********\s\s[END OF TRANSCRIPT]***********+\f'
with no luck.
Any input would be greatly appreciated.